here's the code itself

$basePath='page/2016/10/'; $field='id_page'; $id=1; $name='podborka_vecher_01.jpg,%, podborka_vecher_17.jpg' public function baseSave($basePath,$field,$id,$name){ $transliterator= new Translit(); $bp = array(); if(preg_match('/,%,/',$name)){ $mathes=explode(',%,',$name); foreach ($mathes as $math){ $bp[] = $basePath; $names=$transliterator->traranslitImg($math); $theImage= Image::findOne(['path'=>$basePath, 'name'=>$name ]); if(!isset($theImage)){ $this->path=$basePath; $this->$field=$id; $this->name=$names; $this->insert(); } } }else{ $names=$transliterator->traranslitImg($name); $theImage= Image::findOne(['path'=>$basePath, 'name'=>$name ]); if(!isset($theImage)) { $this->path = $basePath; $this->$field = $id; $this->name = $names; $this->save(); } } } 

I get the following error

 SQLSTATE[HY000]: General error: 1364 Field 'path' doesn't have a default value The SQL being executed was: INSERT INTO `abh_image` (`name`) VALUES ('-podborka_vecher_17.jpg') 

I do not understand where the work has gone with this

 $this->path=$basePath; $this->$field=$id; 

and why only $this->name=$names;

    1 answer 1

    And you do not tell me how it works:

     $this->$field = $id; 

    And why you have a basePath defined and you assign it to an unknown path

     $this->path = $basePath; // должно быть судя логики $this->basePath = $basePath; 

    And that only fulfills

     $this->name = $names; 
    • $this->$field = $id here comes '$ field' model field name in this case 'id_page' $this->path this field of model here they are all 'id', 'id_gods', 'id_post', 'id_cat', 'id_page' ,'path' ,'name' but the point is that at the first iteration of foreach everything works, and in the second such error appears - Sergalas