嗨,我正在研究symfony 3.3项目。我有一个带有choiceType的表单,我想知道读取所选选项的正确方法是什么
控制器代码
$form = $this->createFormBuilder()
->add('decision', ChoiceType::class, array('choices' => array(
'valider' => 'valider',
'rejeter' => 'rejeter',
)
))
->setAction($this->generateUrl('validerRejeter', array('id' => $cours->getId())))
->setMethod('POST')
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$choix=$request->request->get('form');
if ($choix == 'valider')
$cours->setEtat('publié');
else
$em->remove($cours);
$em->flush();
}
答案 0 :(得分:0)
$choix = $form->get('decision')->getData();
或
$choix = $request->request->get('decision');