3
我想在我的symfony項目中使用MinLength驗證程序。Symfony2 - MinLength驗證不起作用 - 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: Error: Class 'Symfony\Component\Validator\Constraints\MinLength' not found in...
@meze,謝謝,我剛剛在symfony網站上找到了這個。有MinLength,請參閱:http://symfony.com/doc/2.2/reference/constraints/MinLength.html –