public function actionCreate() { $model = new Banner(); if ($model->load(\Yii::$app->request->post())) { if ($model->validate() && $model->save()) { return $this->redirect(['index']); } } return $this->render('form', ['model' => $model]); }
/** * Creates a new Banner model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Banner(); $model->weight = 0; $model->region = Banner::REGION_FIRST_COLUMN; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionUploadSubmitNew() { FileHelper::createDirectory(Yii::getAlias('@frontend') . '/web/upload/banner-big'); FileHelper::createDirectory(Yii::getAlias('@frontend') . '/web/upload/banner-thumbs'); $i = 0; $model = new Banner(); if (\yii\web\UploadedFile::getInstances($model, 'file')) { $model->file = \yii\web\UploadedFile::getInstances($model, 'file'); foreach ($model->file as $file) { $i++; $file->saveAs('upload/banner-big/' . $file->name); // Image::thumbnail(Yii::getAlias('@frontend') . '/web/upload/banner-big/' . $file->name , 270, 329) // ->save(Yii::getAlias(Yii::getAlias('@frontend') . '/web/upload/banner-thumbs/' . $file->name ), ['quality' => 80]); $_model = new Banner(); $_model->name = $file->name; $_model->save(); } // foreach($model->file as $file){ // Image::thumbnail(Yii::getAlias('@frontend') . '/web/upload/banner-big/' . $file->name , 270, 329)->save(Yii::getAlias(Yii::getAlias('@frontend') . '/web/upload/banner-thumbs/' . $file->name ), ['quality' => 80]); // } // Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return $this->redirect('/banner/upload'); } }