Phalcon Model Validation

新舊版本的寫法差蠻多的,被舊的 phalcon devtools 自動產生的 model 給陰了..

<?php

use Phalcon\Mvc\Model\Validator\Email as Email;

class Users extends \Phalcon\Mvc\Model
{
    public function validation()
    {
        $this->validate(
            new Email(
                array(
                    'field'    => 'email',
                    'required' => true,
                )
            )
        );

        if ($this->validationHasFailed() == true) {
            return false;
        }

        return true;
    }
}
?>

要改成像這樣... 整個連class namespace 都大改

<?php
use Phalcon\Validation;
use Phalcon\Validation\Validator\Email as Email;
use Phalcon\Validation\Validator\PresenceOf as PresenceOf;

class Users extends \Phalcon\Mvc\Model
{
    public function validation()
    {
        $validation = new Validation();

        $validation-> add(
                "email",
                new Email(
                        ['model' => $this, "message" => "The e-mail is not valid"]
                    )
            );

        return $this->validate($validation);
    }
}
?>