[英]PHP Doctrine Validation
我正在使用理论并尝试验证一些模型。
我的YAML架构中包含以下内容:
User:
package: User
columns:
username:
type: string
notnull: true
notblank: true
minlength: 4
password:
type: string
notnull: true
如果我创建一个新用户,则无论我给它提供什么值,它都会一直进行验证。
例如:
$testuser = new User();
$testuser->username = ' ';
if ( ! $testuser->isValid())
{
echo 'User is invalid!';
}
编辑:上面只是一个示例。 即使省略了在模式中指定为NOT NULL的值,它也仍然有效。
永远不会产生无效的方法。 有谁知道这可能是什么原因? 任何建议表示赞赏。 谢谢。
原因是:在由Doctrine创建的模型中没有isValid()函数。 (在您的模型/生成的/*.php中)
步骤1.请参考《 Doctrine手册》 :您应该将其放在bootstrap.php或任何php文件头中)
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
步骤2.重建模型文件。
步骤3.现在应该可以工作了:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.