2011-10-10 130 views
1

我在Symfony 1,4中生成管理員。我在那裏DoctrineChoice。我想設置這個列表在action.class.php中選擇。如何在後臺窗體中設置默認值?

我複製executeNew到action.class.php,但我不能在加載頁面上設置默認值。

$this->form = $this->configuration->getForm(); 
$this->news = $this->form->getObject(); 
$this->form['author_id']->getWidget()->setOption('choices', '2'); 

不起作用。這可能嗎?

回答

0

此代碼應工作:

$this->form['author_id']->getWidget()->setDefault(2); 

但我不得不說,如果你希望它乾淨,這個代碼屬於Form類,而不是行動。

1

或者只是這樣在LIB /形式

$this->setDefault('fieldname', $value);