You need to know, that checkboxList() will return an array, because you can select multiple options in it; for examle if you check “hello1” and “hello2” you will get:
[“hello1”, “hello2”]
or if you select “hello3” only, you will get:
[“hello3”]
That’s why you are getting this error. If you want to select multiple values:
public function rules() {
return [
[['Cvalues], 'safe'],
];
}
Add this in your beforeSave() - it will save your array as a string:
if ($this->Cvalues&& count($this->Cvalues)) {
$this->Cvalues= Json::encode($this->Cvalues);
}
public function beforeSave($insert) {
if ($this->Cvalues&& count($this->Cvalues)) {
$this->Cvalues= Json::encode($this->Cvalues);
}
return parent::beforeSave($insert);
}