2012-11-25 5 views
2

symfony2 양식으로 작업 중입니다. 이제 "이 값은 null이 아니어야합니다."라는 메시지가 나타납니다. 이제 "이 값"은 무엇입니까? 이 값은? 어떻게 알아낼 수 있을까요? 오류를 덤핑으로symfony2가 "이 값은 null이 아니어야합니다."

: ($ 형상 -> getErrors는()) 좀 하나 formError가 사라졌다 주장 toggeling 후

array (size=3) 
    0 => 
    object(Symfony\Component\Form\FormError)[2418] 
     protected 'messageTemplate' => string 'This value should not be null.' (length=30) 
     protected 'messageParameters' => 
     array (size=0) 
      empty 
     protected 'messagePluralization' => null 
    1 => 
    object(Symfony\Component\Form\FormError)[2420] 
     protected 'messageTemplate' => string 'This value should not be null.' (length=30) 
     protected 'messageParameters' => 
     array (size=0) 
      empty 
     protected 'messagePluralization' => null 
    2 => 
    object(Symfony\Component\Form\FormError)[2421] 
     protected 'messageTemplate' => string 'This value should not be null.' (length=30) 
     protected 'messageParameters' => 
     array (size=0) 
      empty 
     protected 'messagePluralization' => null 

를 얻을. 그 무엇에 의해 :

/** 
    * @ORM\Column(type="integer") 
    * @Assert\NotNull() 
    */ 
protected $price; 

var_dump($reservation->getPrice(), is_null($reservation->getPrice())); 

결과 : 엔티티에

float 733 

boolean false 

그러나 이것은 오류이다는 주장에

..

실패 :

/** 
* @ORM\Column(type="integer") 
* @Assert\NotNull() 
*/ 
protected $price; 

/** 
* @ORM\ManyToOne(targetEntity="Caravan", inversedBy="caravan") 
* @ORM\JoinColumn(name="caravan_id", referencedColumnName="id") 
* @Assert\NotNull() 
*/ 
protected $caravan; 

/** 
* @ORM\Column(type="datetime") 
* @Assert\NotNull() 
*/ 
protected $created; 

사람들은 3 곳이다 isValid 검사 전에 컨트롤러에 설정 한 값입니다. If do :

$form->getData(); 

올바른 데이터가 있습니다.

+0

뿐만 아니라 형태와 연관된 필터의 덤프를 제공하십시오) = isValid 검사 전에 마지막 순간에 바인딩합니다. –

답변

0

문제였다 :

이 작동하지 않습니다 :

작동합니다 :

$reservation->setCreated(new \DateTime()); 

$form->bind($request); 

if($form->isValid()){ 

} 

형태 그가 HES의 유효 여부를 확인합니다 결합합니다. 그 후에 그는 그것을 다시 검사하지 않을 것입니다.

그래서 약간의 조언은,

관련 문제