Symfony2: How to use validators of another Bundle

I am trying to use the FOSUserBundle validators in my own form, but I do not know how to configure validator.yml. Currently, it looks like this:

Acme\UserBundle\Entity\User: constraints: - FOS\UserBundle\Validator\Unique: property: usernameCanonical - FOS\UserBundle\Validator\Unique: property: emailCanonical properties: username: - NotBlank: ~ email: - Email: ~ - NotBlank: ~ mandant: - NotBlank: ~ - Type: Acme\UserBundle\Entity\Mandant 

But this leads to the following PHP error:

 [05-Mar-2012 14:47:56 UTC] PHP Stack trace: [05-Mar-2012 14:47:56 UTC] PHP 1. {main}() W:\redacted\symfony_webfrontend\app\console:0 [05-Mar-2012 14:48:10 UTC] PHP Fatal error: Class 'FOS\UserBundle\ValidatorUnique' not found in W:\redacted\symfony_webfrontend\vendor\symfony\src\Symfony\Component\Validator\Mapping\Loader\FileLoader.php on line 73 

It seems that the class path is wrong, but I cannot find documentation on how to use the validators of another package in my own validators.yml ...

+4
source share
1 answer

Not sure why this works now because I have tried this before, but this seems to be the way:

 namespaces: FOSUserBundle: FOS\UserBundle\Validator\ Acme\UserBundle\Entity\User: constraints: - "FOSUserBundle:Unique": property: usernameCanonical - "FOSUserBundle:Unique": property: emailCanonical properties: username: - NotBlank: ~ email: - Email: ~ - NotBlank: ~ Mandant: - NotBlank: ~ - Type: Acme\UserBundle\Entity\Mandant 
+1
source

Source: https://habr.com/ru/post/1399985/


All Articles