/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $model->uploadImage(); return $model->save() ? $this->redirect(['index']) : var_dump($model); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $model->uploadImage(); $model->date_create = date('Y-m-d'); $model->date_update = date('Y-m-d'); $model->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $image = $model->uploadImage(); if ($image !== false) { $path = $model->getImageFile(); $image->saveAs($path); } // if ($path = $model->upload()) { // $model->preview_image = $path; // } $model->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'authors' => Authors::getAuthorsList()]); } }