ardent icon indicating copy to clipboard operation
ardent copied to clipboard

Add facility to declare scenario in rules

Open sumanta-ghosh opened this issue 9 years ago • 2 comments

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.

sumanta-ghosh avatar Apr 15 '15 08:04 sumanta-ghosh

+1

axyr avatar Jun 18 '15 22:06 axyr

+1

ptsilva avatar Jul 03 '15 03:07 ptsilva