doufei5315 2009-11-29 18:57
浏览 14

PHP Doctrine验证

I'm using doctrine and trying to validate some models.

I have the following in my YAML schema:

User:
  package: User
  columns:
    username:
      type: string
      notnull: true
      notblank: true
      minlength: 4
    password:
      type: string
      notnull: true

If I create a new user, it always validates, regardless of what values I give it.

eg:

$testuser = new User();
$testuser->username = '   ';
if ( ! $testuser->isValid()) 
        {
            echo 'User is invalid!';
        }

EDIT: The above is just an example. It still validates even if values specified as NOT NULL in the schema are omitted.

The invalid method is never produced. Does anyone know what might be causing this? Any advice appreciated. Thanks.

  • 写回答

1条回答 默认 最新

  • dpoxk64080 2009-12-18 12:50
    关注

    the reason is: there's no isValid() function in your models which created by Doctrine. (in your models/generated/*.php)

    Step 1. refer to Doctrine Manual: you should put this in your bootstrap.php or any your php file header)

    $manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
    

    Step 2. rebuild your models' files.

    Step 3. it should work now :)

    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接