如何在后台表单中设置默认值?
我在 Symfony 1,4 中生成了 admin。我那里有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');
不起作用。这可能吗?
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()->setOption('choices', '2');
doesnt work. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者只是像 lib/form 中这样
or just simply like this in lib/form
这段代码应该可以工作:
但我不得不说,如果你想要它干净,这段代码属于 Form 类,而不是操作。
This code should work:
But I have to say that if you want it clean, this code belong to the Form class, not the action.