Rules on model

Hello firends

When I use Yii 1.x and I need to create my rule on model I do it:




public function rules() {

        return array(

           ....

           array('field','MyValidade'),

          ......

       );

}


function MyValidade() {

      //conditions

       $this->addError('field', 'message');

}



How can I do it on Yii 2?

I think this is a good example, covering both client and server side validation.

Hi Alexandre,

It’s almost the same but more flexible in Yii 2.0.

Take a look at the following section of the guide.

Creating Validators

Very good. Thanks guys