2012-01-15 61 views
0

我用Symfony生成了简单的模型。如何用表单GET属性保存?

Job: 
    columns: 
    from_get: { type: integer, notnull: true } 
    type:   { type: string(255) } 
在JobForm.class.php

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

,我有行动:

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

我怎么能保存ID = 3自动from_get?

在JobForm.class.php

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

犯规的工作。

回答

3

我认为访问请求对象的最佳位置是你的模块/动作。

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

    //... your code 
} 

顺便说一下,您可以通过构造函数注入将上下文传递给窗体。请阅读此post以查看可能的实现。