Yii: validation rules that always apply except one scenario

darkheir picture darkheir · Nov 7, 2012 · Viewed 13.5k times · Source

I know that you can have a validation rule that applies only for one scenario:

array('username', 'exist', 'on' => 'update'),

Now i would like to know if it's possible to do the opposite: a rule that applies everytime except for a given scenrio?

The only solution that is see right now is list all the others scenario, but it's not pretty if we need to add some news scenarios later.

array('username', 'exist', 'on' => array('create', 'search', ...),//all the scenarios except update

Answer

rinat.io picture rinat.io · Nov 7, 2012

As of Yii 1.1.11 you can use except keyword:

array('username', 'exist', 'except' => 'update'),

Take a look at this page. There is a little example there.

Doc link