约束验证器唯一

时间:2017-02-21 15:17:15

标签: symfony doctrine-orm orm doctrine

我有这段代码对输入的数据执行唯一验证,然后输入到基础

代码实体:

      public function addAction() {
          $em = $this->getDoctrine()->getManager();
          $request = $this->getRequest();

          if ($request->getMethod() == 'POST') {
          $x= $request->request->get('k');
            for( $i=1;$i<=$x;$i++){

          $nom = $request->request->get('nom'.$i);
          $prenom = $request->request->get('prenom'.$i);
          $age = $request->request->get('age'.$i);
          $class = $request->request->get('sexe'.$i);        
             $cop = new Apps();  
            $cop->setAge($age);
            $cop->setNom($nom);
            $cop->setPrenom($prenom);
            $cop->setClass($class);
            $cop->setPath("path test");
            $validator = $this->get('validator');
  $errors = $validator->validate($cop);

  if (count($errors) > 0) {
      /*
       * Uses a __toString method on the $errors variable which is a
       * ConstraintViolationList object. This gives us a nice string
       * for debugging.
       */
      $errorsString = (string) $errors;

      return new Response($errorsString);
  } else {

            $em->persist($cop);
            $em->flush();
            return new Response('Valide');
             }
           }
              } //end for

           return $this->render('MedBundle:Apps:form.html.twig');

          }

代码控制器:

find tsfolder -name '*.ts' | while read filename; do cat "$filename" >> tsfolder/out.tmp; rm "$filename"; done

它显示错误,但现在问题是errerue的显示效果不好是验证错误消息

的示例
  

对象(test \ MedBundle \ Entity \ Apps).nom:Cette champ existedja。 (代码23bd9dbf-6b9b-41cd-a99e-4844bcf3077f)

请帮助我,谢谢你

0 个答案:

没有答案