2016-10-03 76 views
0

我有一个基于Symfony 2.8的项目,我有一个用CraueFormFlowBundle创建的表单,它允许创建多步表单。我为每个步骤创建了我的流程类和中间表单类型,一切都在这个级别上运行。唯一不起作用的是不会触发单个验证规则,无论是在每个步骤之间还是在表单流程结束时。我在我的实体中使用注释来验证数据。我检查了我的config.ymlvalidationform组件都是enabled,而framework.validation.enable_annotations设置为true在Symfony 2.8中不验证的表格

这里是我的控制器:

public function newEvaluationAction(Classroom $classroom, Subject $subject, Period $period) 
{ 
    $evaluation = $this->getSchoolManager()->createEvaluation($classroom, $subject, $period); 

    $flow = $this->get('app.form.flow.evaluation_create'); 
    $flow->bind($evaluation); 

    $form = $flow->createForm(); 

    if ($flow->isValid($form)) { 
     $flow->saveCurrentStepData($form); 

     if ($flow->nextStep()) { 
      $form = $flow->createForm(); 
     } else { 
      $this->getSchoolManager()->persistEvaluation($evaluation); 
      $this->redirectToRoute('ec_classroom_show_subject', [ 
       'subject' => $subject->getId() 
      ]); 
     } 
    } 

    return $this->render('classrooms/subjects/evaluations/new.html.twig', [ 
     'form' => $form->createView(), 
     'flow' => $flow, 
     'classroom' => $classroom, 
     'subject' => $subject, 
     'period' => $period, 
     'evaluation' => $evaluation 
    ]); 
} 

和我Evaluation实体

<?php 

namespace AppBundle\Entity; 

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\Common\Collections\Collection; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 

/** 
* @ORM\Entity(
*  repositoryClass="AppBundle\Repository\EvaluationRepository" 
*) 
*/ 
class Evaluation 
{ 
    /** 
    * @var integer 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue 
    */ 
    private $id; 

    /** 
    * @var string 
    * @ORM\Column(type="string") 
    * @Assert\NotBlank() 
    * @Assert\Length(max=255) 
    */ 
    private $label; 

    /** 
    * @var \DateTime 
    * @ORM\Column(type="date") 
    * @Assert\NotNull() 
    * @Assert\Date() 
    */ 
    private $date; 

    /** 
    * @var Collection 
    * @ORM\ManyToMany(targetEntity="Knowledge") 
    * @Assert\Count(min=1, minMessage="evaluation.knowledges.at_least_one") 
    */ 
    private $knowledges; 

    /** 
    * @var Collection|Scale[] 
    * @ORM\OneToMany(targetEntity="Scale", mappedBy="evaluation", cascade={"ALL"}) 
    * @Assert\Count(min=1, minMessage="evaluation.scales.at_least_one") 
    * @Assert\Valid(traverse=true) 
    */ 
    private $scales; 

    /** 
    * @var Subject 
    * @ORM\ManyToOne(targetEntity="Subject") 
    * @ORM\JoinColumn(nullable=false) 
    */ 
    private $subject; 

    /** 
    * @var Period 
    * @ORM\ManyToOne(targetEntity="Period") 
    * @ORM\JoinColumn(nullable=false) 
    */ 
    private $period; 

    /** 
    * @var Classroom 
    * @ORM\ManyToOne(targetEntity="Classroom") 
    * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") 
    */ 
    private $classroom; 

    /** 
    * @var Composition[]|Collection 
    * @ORM\OneToMany(targetEntity="Composition", mappedBy="evaluation", cascade={"all"}) 
    * @Assert\Valid(traverse=true) 
    */ 
    private $compositions; 

他们更多的实体验证(见Evaluation实体关系),而不是连Evaluation本身,而不协会,未经验证。我能做些什么来让每个验证规则都被检查?

回答

0

找到解决方案:CraueFormFlowBundle为流程的每个步骤创建验证组名称。在我的情况下,我的createEvaluation流程(流程的getName方法给出的名称)的第一步的验证组名为flow_evaluation_create_step1。我必须在Assert注释中设置要验证的权限字段的groups属性(即在当前步骤中编辑的人员)。