Php 如何在后端表单中设置默认值?
我在Symfony 1,4中生成了admin。我有很多理论。我想在action.class.php中设置此列表 我将executeNew复制到action.class.php,但无法在加载页面上设置默认值Php 如何在后端表单中设置默认值?,php,symfony1,doctrine,symfony-1.4,Php,Symfony1,Doctrine,Symfony 1.4,我在Symfony 1,4中生成了admin。我有很多理论。我想在action.class.php中设置此列表 我将executeNew复制到action.class.php,但无法在加载页面上设置默认值 $this->form = $this->configuration->getForm(); $this->news = $this->form->getObject(); $this->form['author_id']->getWidget(
$this->form = $this->configuration->getForm();
$this->news = $this->form->getObject();
$this->form['author_id']->getWidget()->setOption('choices', '2');
不起作用。这可能吗?此代码应该可以工作:
$this->form['author_id']->getWidget()->setDefault(2);
但是我必须说,如果您希望它干净,那么这段代码属于Form类,而不是action。这段代码应该可以工作:
$this->form['author_id']->getWidget()->setDefault(2);
但是我必须说,如果您希望它干净,那么这段代码属于Form类,而不是action。或者只是像lib/Form中这样
$this->setDefault('fieldname', $value);
或者简单地像lib/form中这样
$this->setDefault('fieldname', $value);