开发者

how to set default value in backend form?

开发者 https://www.devze.com 2023-04-11 16:28 出处:网络
i generated admin in Symfony 1,4. I have there DoctrineChoice. I would like set this list select in action.class.php.

i generated admin in Symfony 1,4. I have there DoctrineChoice. I would like set this list select in action.class.php.

I copied executeNew to action.class.php, but i dont can set default value on load page.

$this->form = $this->configuration->getForm();
$this->news = $this->form->getObject();
$this->form['author_id']->getWidget()->setOptio开发者_如何转开发n('choices', '2');

doesnt work. Is this possible?


or just simply like this in lib/form

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


This code should work:

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

But I have to say that if you want it clean, this code belong to the Form class, not the action.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号