我正在尝试以我自己的形式使用FOSUserBundle的验证器,但我不知道如何设置validator.yml。它目前看起来像这样:
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
但是这会导致以下PHP错误:
[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
看起来类路径错了但我找不到任何关于如何在我自己的validators.yml中使用不同包的验证器的文档......
答案 0 :(得分:1)
不确定为什么它现在真的有效,因为我之前尝试过这个,但这似乎是要走的路:
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