Validator interface

I just write something like this:

use Phalcon\Validation\Validator\Between;

class Users extends \Phalcon\Mvc\Model {
    public function validation() {
        $this->validate(new Between(array(
            'minimum' => 3,
            'maximum' => 21,
            'field' => 'nickname',
            'message' => 'reg_error_nick_len'

And when I try to save model I have this exception trace (uniquness and email work normal):

Unexpected value type: expected object implementing Phalcon\Mvc\Model\ValidatorInterface, object of type Phalcon\Validation\Validator\Between given
\#0 W:\domains\\app\models\Users.php(60): Phalcon\Mvc\Model->validate(Object(Phalcon\Validation\Validator\Between))
\#1 [internal function]: Users->validation()
\#2 [internal function]: Phalcon\Mvc\Model->fireEventCancel('validation')
\#3 [internal function]: Phalcon\Mvc\Model->_preSave(Object(Phalcon\Mvc\Model\MetaData\Memory), true, 'id')
\#4 W:\domains\\app\controllers\AuthorizationController.php(88): Phalcon\Mvc\Model->save(Array, Array)
\#5 [internal function]: AuthorizationController->finishAction()
\#6 [internal function]: Phalcon\Dispatcher->dispatch()
\#7 W:\domains\\public\index.php(32): Phalcon\Mvc\Application->handle()
\#8 {main}


Phalcon\Validation\Validator\Between is a validator that belongs to the Phalcon\Validation component, not to Phalcon\Mvc\Model

And what i need to to? (:


That's why you're getting that exception, what is exactly the question?

How i can write this validation in my model?

edited Sep '14

Phalcon has diffirent validation classes for forms and models.

To build validator for a model you need to extend Phalcon's Phalcon\Mvc\Model\Validator abstract class with an API described here

It is not described in the docs how to do this (validators for models).

I think it is very smiliar to creating forms validators. And this is described. You can read about it in the docs here or this is my post