I'm trying to get a clean error message after validating my Subscribe Entity :
/**
* 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;
After calling the validator service and test it with blank email:
$validator = $this->get('validator');
$errors = $validator->validate($email);
if (count($errors) > 0) {
return new JsonResponse((string)$errors);
}
I got this validation message :
Object(AppBundle\Entity\Subscribe).email: This value must not be empty. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3).
Any idea how to clean it ?