【发布时间】:2011-06-01 22:27:15
【问题描述】:
我正在尝试使用 symfony2 构建自定义验证器,但发生了一些奇怪的事情:
我已经按照symfony2 cookbook 中的步骤创建了密码和密码验证,但是第一次加载页面时出现此错误:
AnnotationException: [Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\Password" in property NMSP\MyBundle\Entity\User::$password does not exist, or could not be auto-loaded.
重新加载后错误消失,验证仍然没有触发,它返回代码是有效的。
这里是相关代码:
//annotation declaration:
/**
* @ORM\Column(type="string", length="32", unique="true")
*
* @Assert\MinLength(3)
* @Assert\Password2()
*/
protected $password;
//load files with the following in the code
services:
validator.password:
class: NMSP\MyBundle\Validator\PasswordValidator
tags:
- { name: validator.constraint_validator, alias: password }
想不出来这个:(
【问题讨论】:
标签: validation symfony