/** * Creates a new Portfolio model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Portfolio(); //$model->image = UploadedFile::getInstance($model, 'image'); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->image = UploadedFile::getInstance($model, 'image'); if ($model->validate() and isset($model->image)) { // $target = 'uploads/' . $model->id . '.' . $model->image->extension; //print $target; $model->image->saveAs($target); //print $target; } $model->logo = UploadedFile::getInstance($model, 'logo'); if ($model->validate() and isset($model->logo)) { // $target = 'uploads/' . $model->id . '_logo.' . $model->logo->extension; //print $target; $model->logo->saveAs($target); //print $target; } //die('1'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Portfolio model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Portfolio(); if ($model->load(Yii::$app->request->post())) { //$imageName = $model->file->baseName; $model->file = UploadedFile::getInstance($model, 'port_image'); $model->file->saveAs('../../frontend/web/uploads/portfolio/' . $model->file->baseName . '.' . $model->file->extension); $model->port_image = 'uploads/portfolio/' . $model->file->baseName . '.' . $model->file->extension; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }