PHP条令验证

PHP条令验证,php,validation,doctrine,Php,Validation,Doctrine,我正在使用理论并试图验证一些模型 我的YAML模式中有以下内容: User: package: User columns: username: type: string notnull: true notblank: true minlength: 4 password: type: string notnull: true 如果我创建了一个新用户,无论我给它什么值,它都会进行验证 例如: 编辑:

我正在使用理论并试图验证一些模型

我的YAML模式中有以下内容:

User:
  package: User
  columns:
    username:
      type: string
      notnull: true
      notblank: true
      minlength: 4
    password:
      type: string
      notnull: true
如果我创建了一个新用户,无论我给它什么值,它都会进行验证

例如:

编辑: 以上只是一个例子。即使省略了模式中指定为NOTNULL的值,它仍然会进行验证

永远不会生成无效的方法。有人知道这可能是什么原因吗? 谢谢你的建议。
谢谢。

原因是:由Doctrine创建的模型中没有isValid()函数。(在您的模型中/generated/*.php)

第一步。 请参阅:您应该将其放在bootstrap.php或任何php文件头中)

第二步。 重建模型的文件

第三步。
它现在应该可以工作了:)

原因是:您的模型中没有由Doctrine创建的isValid()函数。(在您的模型中/generated/*.php)

第一步。 请参阅:您应该将其放在bootstrap.php或任何php文件头中)

第二步。 重建模型的文件

第三步。 它现在应该可以工作了:)

$testuser = new User();
$testuser->username = '   ';
if ( ! $testuser->isValid()) 
        {
            echo 'User is invalid!';
        }
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);