phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.76k stars 1.98k forks source link

[BUG][1.3.0] Model validation fails if it's manual... #2151

Closed lantian closed 10 years ago

lantian commented 10 years ago

https://github.com/phalcon/cphalcon/blob/1.3.0/ext/mvc/model.c#L2268 Throws an exception ErrorException: First argument is not an array

With code:

    public function validation()
    {
        $this->validate(new Uniqueness(["field" => "username"]));
        $this->validate(new Uniqueness(["field" => "email"]));
        $this->validate(new Email(["field" => "email", "required" => true]));
        $this->validate(new StringLength(["field" => "password", "min" => 6]));

        return $this->validationHasFailed() !== true;
    }

If you manually runs:

$model->validation();

This is cozed by _errorsMessages = null; Fast fix for this:

public function validation()
{
    if ($this->_errorMessages === null) {
        $this->_errorMessages = [];
    }

    ...
}
dreamsxin commented 10 years ago

I'll try to fix it.

lantian commented 10 years ago

Thanks