@Ainur123

Почему не сохраняются записи в бд?

почему не сохраняются записи в бд? Yii2. Дело не в пути.
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;
    };
}
  • Вопрос задан
  • 80 просмотров
Пригласить эксперта
Ответы на вопрос 1
@Akellacom
CTO
У вас скорее всего не проходит валидация, посмотрите правила в модели
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы