Answer the question
In order to leave comments, you need to log in
Explain why this strange behavior when saving?
here is the actual code
$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();
}
}
}
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')
$this->path=$basePath;
$this->$field=$id;
$this->name=$names;
$this->$field = $id
here the $field
name of the model field comes in in this case 'id_page'
$this->path
this is the model field here they are all'id', 'id_gods', 'id_post', 'id_cat', 'id_page' ,'path' ,'name'
the bottom line is that at the first iteration of foreach everything works on the second iteration, such an error appears.
Answer the question
In order to leave comments, you need to log in
1. you $basePath='page/2016/10/';
or public $basePath='page/2016/10/';
?
2. What's in your rules?
3. For an accurate answer - lay out the entire model, not a piece of it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question