【发布时间】:2015-09-16 11:01:03
【问题描述】:
我的表单中有以下实体字段:
->add('cover_recto_color', 'entity', [
'label' => 'printers_products.cover_recto_color.label',
'multiple' => true,
'expanded' => true,
'class' => 'VeoprintVeoProductBundle:VeoColor',
'property' => 'name',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('vc')
->innerJoin('vc.rectoProducts', 'p')
->where('p.family = :family')
->setParameter('family', $this->_family)
;
}
])
此字段检索一组数据以使用复选框列表显示它。我想在此列表中添加另一个自定义选项,表示数据库中的 NULL 值,但表示应用程序的具体值。
我尝试编辑 finishView 函数中的选项:
public function finishView(FormView $view, FormInterface $form, array $options)
{
$new_choice = new ChoiceView(null, 'value', 'label');
$view->children['cover_recto_color']->vars['choices'][] = $new_choice;
}
但它不起作用。 buildView 函数也一样。
我该怎么办?
【问题讨论】:
-
为
entity创建一个form type extension。添加一个新选项(即custom_choice)并使用buildView应用该选项。 -
谢谢。一位同事也以这种方式指导我,我会检查一下。
标签: symfony