ardent
ardent copied to clipboard
Add facility to declare scenario in rules
I want to specify which rules will be applied when going to call $model->save(). User can mention scenario explicitly, there may be some default scenario 'create','update'.
$model->scenario='update';
$rules = array(
'onUpdate.name' => 'required|min:3|max:80|alpha_dash',
'onCreate.email' => 'required|between:3,64|email|unique:users',
'password' => 'required|alpha_num|between:4,8|confirmed',
'password_confirmation' => 'required|alpha_num|between:4,8'
);
So email rule will not be applied in update scenario, all others rules will be applied to all scenario.Mainly I want some Yii validation flavor. Using this we don't need to provide extra rules from controller, single location for all rules.
+1
+1