次のようなドキュメントで定義されているように、コールバック検証制約を使用しています:-
/**
* GD\AdminBundle\Entity\Offer
*
* @ORM\Table(name="offers")
* @ORM\Entity(repositoryClass="GD\AdminBundle\Repository\OfferRepository")
* @Assert\Callback(methods={"isDateValid"})
*/
class Offer
{
...
public function isDateValid(ExecutionContext $context)
{
// This code block gets executed but $this->getEndDate() is NULL
if( $this->getEndDate()->getTimestamp() < $this->getStartDate()->getTimestamp() ){
$context->addViolation('End Date cannot be less than Start Date.', array(), null);
}
}
ただし、var_dump を実行してテストすると$this->getEndDate()
、NULL
SonataAdminBundle を使用して、管理者から新しいオファー インスタンスを作成しています。 ここで何が間違っていますか?