Answer the question
In order to leave comments, you need to log in
Why are records not saved to the database?
Why are records not saved to the database? Yii2. It's not about the path.
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->gallery = UploadedFile::getInstances($model, 'gallery');
$model->uploadGallery();
$model->file = UploadedFile::getInstance($model, 'file');
if ($model->file){
$model->upload();
}
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
public function upload(){
if($this->validate()){
$path ='upload/store/' . $this->file->baseName . '.' . $this->file->extension;
$this->file->saveAs($path,false);
$this->attachImage($path);
@unlink($path);
return true;
} else {
return false;
}
}
public function uploadGallery()
{
if ($this->validate()) {
foreach($this->gallery as $files){
$path ='upload/store/' . $files->baseName.'.'.$files->extension;
$files->saveAs($path,false);
$this->attachImage($path);
@unlink($path);
}
return true;
} else {
return false;
};
}
Answer the question
In order to leave comments, you need to log in
Your validation most likely does not pass, look at the rules in the model
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question