我正在尝试在我的 symfony 项目中使用 th MinLength 验证器。
这是我使用它的方式:
use Symfony\Component\Validator\Constraints\MinLength;
class RegisterNewUser
{
protected $password;
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
if( isset( $metadata->properties["password"] ) )
unset($metadata->properties["password"]);
$password_blank = new NotBlank();
$password_min = new MinLength(5);
$password_blank->message = "The password should not be blank";
$password_min->message = "The password is too short. It should have {{ limit }} characters or more";
$metadata->addPropertyConstraint('password', $password_blank);
$metadata->addPropertyConstraint('password', $password_min );
}
}
我收到的错误消息是:
FatalErrorException:错误:在...中找不到类“Symfony\Component\Validator\Constraints\MinLength”