/** * Creates a new Shop model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Shop(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { /** Handle uploaded file **/ $image = UploadedFile::getInstance($model, 'imageFile'); if ($image instanceof UploadedFile) { $suffix = ''; while (!file_exists($filePath = Yii::getAlias("@webroot/" . Shop::REPOSITORY . ($fileName = $image->baseName . $suffix . $image->extension)))) { $suffix += 1; $image->saveAs($filePath); } $model->image = $fileName; } /** Save the model **/ if ($model->save()) { return $this->redirect(['view', 'id' => $model->name]); } else { return $this->render('createShop', ['model' => $model]); } } else { return $this->render('createShop', ['model' => $model]); } }