Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的表单构建器中,使用实体选择字段,我可以通过以下方式检索实体的内容:
$builder->add('manufacturer', 'entity', array('class' => 'Manufacturer'....
一切正常,选择框在视图中正确呈现。但是,我想在名为“添加新”的选择框中添加一个额外的选项(它不会映射到实体),这将导致选择框包含制造商选项,最后添加一个添加新选项。实现这一目标的最佳 Symfony2 方法是什么?
public function finishView(FormView $view, FormInterface $form, array $options) { $new_choice = new ChoiceView(null, 'value', 'label'); $view->children['manufacturer']->vars['choices'][] = $new_choice; }