Rules for different actions in same model.


In my controller i have two actions, MyProfile and Update.

Some rules are common, while some are unique to each action.

this is how i am trying to seperate the rules

      array('password1','CheckCurrentPassword','on'=>'MyProfile' ),

        array('EMAIL', 'CheckIfUnique', 'on'=>'Update'),

Somehow, when i specify the ‘on’ attribute, the control does not enter functions ‘CheckCurrentPassword’ or ‘CheckIfUnique’.

If i take out the on clause, then all seems to work fine, but the validation rules clash for all the actions.

Can anybody tell me if I am doing something wrong ?



you must specify the scenario if you validate the model.

the on index is for the scenario name. so you can have ‘on’=>‘update’

when you instantiate the model like $obj = new NameOfModel();

you then set the secnario in 1.1 like $obj->scenario = ‘update’;

then the rules where on is set to update will apply along with those where on is not specified.

Great…that was super fast. Thanks so much.

I specified my scenario in this way.


Is this also a correct way of doing it, or, will it be deprecated ?



i think that should work in all versions prior to 1.1a

thanks helped great