Unique validation rule

I’m triying to create a unique validation rule for a field if it is not empty.

The code I’ve tried:

[['kod'], 'unique'],


['kod', 'unique', 'when' => function($model){

				return $model->kod !== ''; //!empty($model->kod);

			}, 'enableClientValidation' => false],


['kod', 'validateKod', 'when' => function($model){

				return $model->kod !== ''; //!empty($model->kod);


But in every case I get the error:

Response content must not be an array.

The field’s ‘kod’ value is just a string not array.

Where do you get that error?

If you mean in what action then it is in update.

No I mean where does that error show up? JS? PHP?

PHP, no js actions, just a standard action on update a record.

The error comes up on saving the record.

Please post the code that actually causes the error and specify in which line it occurs.