在实体回调中添加Symfony Assert

时间:2017-12-03 10:19:06

标签: symfony symfony-3.3

如何在实体回调中添加Symfony Assert(Notblank(); Number(); Email(); ...)?

示例AppBundle\Entity\TrainingLead

/**
 * @Assert\Callback
 */
public function rejectedValidate(ExecutionContextInterface $context)
{
    if (null !== $this->rejectedAt) {
        // How to add "Assert\NotBlank()" in rejectedContent" ?
        $context->buildViolation('training_lead.reason')
            ->atPath('rejectedContent')
            ->addViolation()
        ;
    }
}

0 个答案:

没有答案