当我坚持实体时,我想在表单中添加一个按钮。那可能吗。我读了很多关于修改实体的内容,但这不是我想要做的,我只是想添加一个按钮。
if($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
.... what do I write here to add my button ? is it even here or the type ?
谢谢 }
答案 0 :(得分:0)
我找到了一个解决方案,它实际上是可能的。必须先创建formView,然后再检查表单是否已提交或有效
$form_builder->add('button', 'boutons', array('attr' => array('boutons' => $buttons))); //boutons is a type field I created and I have to give an array of buttons I want to add)
$form = $form_builder->getForm();
$form->handleRequest($request);
$form_view = $form->createView();
if($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $form->getData();
$em->persist($entity);
if($form_view->offsetExists('button')) {
$form_view->children['button']->vars['attr']['boutons'][] = $button_send_validation; (// I add my new button to the array of buttons)
}
}
希望它可以帮助别人..