3
我有一些領域我跟實體:爲什麼我的選擇領域仍然需要?
/**
* @ORM\Column(type="string", length=6, nullable=true)
* @Assert\Choice(choices = {"male", "female"})
*/
protected $gender;
和創建聯繫人形式:
$builder->add('firstName')
->add('lastName')
->add('email')
->add('gender','choice',array(
'choices' => array('male' => 'male', 'female' => 'female'),
'required' => false,
));
這將導致一個不是強制性場AFAIK。 仍然表單告訴我,我必須選擇一個性別。 有什麼建議嗎?
SORRY!我改變了代碼,使其更容易理解,不幸的是我搞砸了,因此你的答案是正確的,但解決了另一個問題。我剛剛編輯了我的問題 - 現在它代表了我的真實問題。 – stoefln 2012-03-08 12:22:39
也許Assert \ Choices註釋與可爲空的值不兼容。或嘗試此註釋@Assert \ Choice(選擇= {「男性」,「女性」,null}) – AlterPHP 2012-03-08 14:19:07
謝謝,工作! – stoefln 2012-03-09 13:08:33