如何使用表单GET属性保存?

问题描述:

I generated simply model with Symfony.

Job:
  columns:
    from_get:  { type: integer, notnull: true }
    type:         { type: string(255) }

in JobForm.class.php:

$this->setWidget('from_get', new sfWidgetFormInputHidden());

and i have action:

http://mysite.com/job/new?get=3

How can i save id=3 to from_get automatically?

in JobForm.class.php

$this->setDefault('from_get', $this->request->getParemeter('get'));

doesnt working.

I think the best place to access the request object is your module/action.

//in your module job
public function executeNew(sfWebRequest $request)
{
  $this->form = new JobForm();
  $this->form->setDefault('from_get', $request->getParameter('get'));

  //... your code
}

By the way, you can pass the context to the form via constructor injection. Please read this post to see a possible implementation.