【发布时间】:2017-10-29 00:17:10
【问题描述】:
验证我的订阅实体后,我正试图获得一条干净的错误消息:
/**
* Subscribe
* @UniqueEntity("email")
* @ORM\Table(name="subscribe")
* @ORM\Entity(repositoryClass="AppBundle\Repository\SubscribeRepository")
*/
class Subscribe
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @Assert\NotBlank()
* @Assert\Email()
* @ORM\Column(name="email", type="string", length=255, nullable=true, unique=true)
*/
private $email;
调用验证器服务并使用空白电子邮件进行测试后:
$validator = $this->get('validator');
$errors = $validator->validate($email);
if (count($errors) >0) {
return new JsonResponse( (string)$errors);
}
我收到了这条消息Object(AppBundle\Entity\Subscribe).email: This value must not be empty. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)。
知道怎么清洗吗?
【问题讨论】:
标签: php symfony symfony-2.1 symfony-3.2