Symfony:选择字段中的所选选择始终为空

Symfony:选择字段中的所选选择始终为空,symfony,Symfony,请帮帮我,我正在处理这个问题,我没有太多时间,我是symfony的新手,我自己无法解决这个问题!!:( 我有一个表单包含一个动态选择字段,当它提交时,我收到一个错误: An exception occurred while executing 'INSERT INTO userprof (id_profil) VALUES (?)' with params [null]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column

请帮帮我,我正在处理这个问题,我没有太多时间,我是symfony的新手,我自己无法解决这个问题!!:( 我有一个表单包含一个动态选择字段,当它提交时,我收到一个错误:

An exception occurred while executing 'INSERT INTO userprof (id_profil) VALUES (?)' with params [null]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id_profil' cannot be null
因此,问题要么出现在所选的选项
$lib_userprof=$request->request->get('profils');
中,要么出现在
$idProf=$rep->findOneBy($lib_userprof);

代码如下:

$user = new user();
        $profils=$rep->findAll();

        $j=0;
        $profArr[]=array();
        foreach ($profils as $p) {
            $libelle= $p->getLibelle();

            $profArr[$j]=$libelle;
            $j=$j+1;

        }
        $form2 = $this->createFormBuilder($user,array('csrf_protection' => false))
            ->add('id', 'text',array('attr'=>array("autocomplete" => "off",'name'=>'login_user','required'=>'required',
                'maxlength'=>'255','placeholder'=>'Matricule')))
            ->add('password', 'password',array('attr'=>array('autocomplete' => 'off','placeholder'=>'Mot de passe','required'=>'required')))
            ->add('profils', 'choice'
                ,array( 'choices' => array('Profils' => $profArr),'mapped'=>false),
                array('attr'=>array('required'=>'required')))
            ->add('Ajouter', 'submit', array('attr' => array('class' => 'btn btn-primary btn-block rounded_btn', 'id' => 'login_btn',
                'style' => "width:6vw;height:5vh;padding:0px 0px; position:relative;left:5vmin;top:1vmin;font-size:2vmin;")))
            ->getForm();


        $form2->handleRequest($request);
        $id = $request->request->get('id');
        $pwd= $request->request->get('password');
        $lib_userprof=$request->request->get('profils');
        $userprof=new userprof();
        if ($form2->isSubmitted() && $form2->isValid()) {
            $em=$this
                ->getDoctrine()
                ->getManager();
            //$lib_userprof=$request->request->get('profils');
            $idProf=$rep->findOneBy($lib_userprof);
            $id=$request->request->get('id');
            //$userprof->setId($id);
            //$userprof->setIdProfil($id_userprof);
            $em->persist($userprof);
            $em->flush();


            $user->setId($id);
            $user->setPassword($pwd);

            $user->setEtat(true);
            //$em->merge($user);
            $em->persist($user);
            $em->flush();
            return $this->redirectToRoute('userProf', array('users'=>$users,
                'form2'=>$form2->createView()
            ));
var_dump($lib_userprof);
        }

如果您知道这是两个可能的错误源之一,则转储这两个错误源,并确保它们符合您的预期。此外,您的类Userprof应大写。您有一行$Userprof=new Userprof();该行可能应为$Userprof=new Userprof();不,我的类名是“userprof”,我转储了这两个类,但当我收到错误时,转储不会返回任何内容:(