0

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 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.