symfony获取所选的choiceType值

时间:2018-04-28 15:33:18

标签: php symfony symfony-3.3

嗨,我正在研究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();
    }

1 个答案:

答案 0 :(得分:0)

$choix = $form->get('decision')->getData();

$choix = $request->request->get('decision');