私は symfony2 フォームで作業していますが、「この値は null であってはなりません。」というメッセージが表示されます..「THIS VALUE」..この値は何ですか? そしてそれを理解する方法は?
エラーをダンプすることにより: ($form->getErrors())
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
いくつかのアサートを切り替えた後、1 つの formError がなくなりました。それは何によって:
/**
* @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;
これらは、isValid チェックの前にコントローラーに設定した 3 つのプロパティです。
$form->getData();
正しいデータがあります。