Advanced components - Validators - Analyzing the ErrorStack.php 905 Bytes
Newer Older
doctrine's avatar
doctrine committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
try {
    $user->name = "this is an example of too long name";
    $user->Email->address = "drink@@notvalid..";
    $user->save();
} catch(Doctrine_Validator_Exception $e) {
    $stack = $e->getErrorStack();
    foreach($stack as $component => $err) {
        foreach($err as $field => $type) {
            switch($type):
                case Doctrine_Validator::ERR_TYPE:
                    print $field." is not right type";
                break;
                case Doctrine_Validator::ERR_UNIQUE:
                    print $field." is not unique";
                break;
                case Doctrine_Validator::ERR_VALID:
                    print $field." is not valid";
                break;
                case Doctrine_Validator::ERR_LENGTH:
                    print $field." is too long";
                break;
            endswitch;
        }
    }
}
?>