views:

559

answers:

1

Hi, 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.

+2  A: 

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 :)

dwchiang