is there a way to apply a rule on Model by condition?
I mean something like that
public function rules() {
array('specialattribute', 'numerical', 'integerOnly' => true,
'when'=>'Yii::app()->user->checkAccess("superadmin") or a method'),
}
instead of
public function rules() {
array('specialattribute', 'numerical', 'integerOnly' => true,
'on'=>'superadmin'),
}
to avoid the repeateding set of scenario in Controllers/action
I have used that in config/main.php, accessRules in Controller etc
I did’t think that the same thing could be applied also in rules method (although it is exactly the same thing!)
I have used both condition way and Expressions in accessRules, so I thought there was something like Expressions in models rules.
Yes I could use conditions in custom validators, but why did you say ‘not use scenarios’? Controllers could set the scenarios of the model by condition so the results are the same, Please tell me if it is best way and why.