2011-10-10 132 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);