Ejemplo n.º 1
0
        $this->fields['email'] = new Field('email');
    }
    protected function before_save()
    {
        $this->validates_presence_of('name', 'address')->message('%s should be filled!');
        $this->validates_length_of('name')->in(1, 5)->too_short('Too short: %s [min: %d]')->too_long('Too long: %s, [max: %d]');
        $this->validates_length_of('address')->max(5)->too_long('%s is too long, maximum is %d charachters');
        $this->validates_numericality_of('phone');
        $this->validates_format_of('email')->with('/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i');
        return true;
    }
}
class ActiveRecordHelper extends Object
{
    public static function error_messages_for(ActiveRecord $record)
    {
        foreach ($record->getFields() as $field) {
            foreach ($field->getErrors() as $error) {
                echo $error . "\n";
            }
        }
    }
}
$p = new Person();
$p->email = 'F';
$p->phone = 'a';
$p->name = 'Marel';
$p->address = 'Andro';
var_dump($p->save());
ActiveRecordHelper::error_messages_for($p);