2012-01-15 5 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')); 

のdoesntの作業で

答えて

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をお読みください。

関連する問題