/** * Creates a new Data model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Data(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->image = \yii\web\UploadedFile::getInstance($model, 'image'); if ($model->image) { $path = __DIR__ . '/../../frontend/web/images/store/' . $model->image->baseName . '.' . $model->image->extension; $model->image->saveAs($path); $model->attachImage($path); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }