【发布时间】:2016-05-30 11:38:44
【问题描述】:
我有一个关于在 symfony2 中管理表单的问题。所以在我的控制器中我有:
$form = $this->createForm(SubMenuType::class);
在我的 SubMenuType 类中:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$aTemplate = Template::$aTemplates;
$aMenu = $this->getDoctrine()->getRepository('AppAdminBundle:Menu')->findAll();
$builder
->add('name', TextType::class)
->add('template',ChoiceType::class, array('choices' => $aTemplate,'choices_as_values' => true))
->add('menu',ChoiceType::class, array('choices' => $aMenu,'choices_as_values' => true))
->add('save',SubmitType::class, array('label'=> 'Save'))
;
}
问题是:如何从 SubMenuType 的菜单实体中获取 $aMenu 数据?请帮我。提前谢谢
【问题讨论】:
-
你的意思是:*"如何从这个 SubMenuType 的菜单实体中获取 $aMenu 数据" *?
-
@felipsmartins 如何在 SubMenuType 中使用
$this->getDoctrine()->getRepository('AppAdminBundle:Menu')->findAll()? -
好的,如果我理解得很好,应该会有所帮助(我之前已经回答过):Load options into drop down on a form based on user's id in symfony 2 或 [aaaa]Symfony forms (as standalone component with Doctrine) EntityType not working