skip yii2 unique validation on update action if new value equals to prev value -


because of unique validator error on update action ('this username taken') wanna validate username on update action when new username value not equals prev value, it's rule:

        [['username'], 'unique', 'on'=>'update', 'when' => function($model){                 return static::getoldusername($model->id) !== $model->username;             }         ], 

and it's function prev username value:

public static function getoldusername($id) {     return static::findidentity($id)->username; } 

but doesn't work, think $model->getid() return nothing because of static id (e.g: 23) work.

        [['username'], 'unique', 'on'=>'update', 'when' => function($model){                 return static::getoldusername(23) !== $model->username;             }         ], 

how can model id? or if have other ways skip yii2 unique validation on update action if new value equals prev value, please explain it.

thanks in advance

i should code right , works now, error comes ,. oops!!

i hope question useful other viewers, thanks.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -