2016-10-03 73 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屬性(即在當前步驟中編輯的人員)。