1
我想驗證後,我的訂閱實體,以得到一個乾淨的錯誤消息後:
如何獲得錯誤信息實體驗證
/**
* 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)
。 任何想法如何清潔它?
好兄弟爲我工作的各個領域的工作,非常感謝你:) – ahmedbhs
很高興爲您服務! :d –