/** * Creates a new Categories model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Categories(); if ($model->load(Yii::$app->request->post())) { // If alias is not set, generate it if ($_POST['Categories']['alias'] == "") { $model->alias = $model->generateAlias($model->name); } // Genarate Json Params $params = array('categoriesImageWidth' => $_POST['categoriesImageWidth'], 'categoriesViewData' => $_POST['categoriesViewData'], 'categoryImageWidth' => $_POST['categoryImageWidth'], 'categoryViewData' => $_POST['categoryViewData'], 'itemImageWidth' => $_POST['itemImageWidth'], 'itemViewData' => $_POST['itemViewData']); $params = $model->generateJsonParams($params); $model->params = $params; // Upload Image and Thumb if is not Null $imagePath = Yii::getAlias('@webroot') . "/" . Yii::$app->controller->module->categoryImagePath; $thumbPath = Yii::getAlias('@webroot') . "/" . Yii::$app->controller->module->categoryThumbPath; $imgNameType = Yii::$app->controller->module->imageNameType; $imgOptions = Yii::$app->controller->module->thumbOptions; $imgName = $model->name; $fileField = "image"; // Create UploadFile Instance $image = $model->uploadFile($imgName, $imgNameType, $imagePath, $fileField); if ($model->save()) { // upload only if valid uploaded file instance found if ($image !== false) { // save thumbs to thumbPaths $thumb = $model->createThumbImages($image, $imagePath, $imgOptions, $thumbPath); } // Set Success Message Yii::$app->session->setFlash('success', Yii::t('articles.message', 'Category has been created!')); return $this->redirect(['view', 'id' => $model->id]); } else { // Set Error Message Yii::$app->session->setFlash('error', Yii::t('articles.message', 'Category could not be saved!')); return $this->render('create', ['model' => $model]); } } else { Yii::$app->session->setFlash('error', Yii::t('articles.message', 'Category could not be saved!')); return $this->render('create', ['model' => $model]); } }
/** * Creates a new Categories model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed * @throws ForbiddenHttpException */ public function actionCreate() { // Check RBAC Permission if ($this->userCanCreate()) { $post = Yii::$app->request->post(); $model = new Categories(); if ($model->load($post)) { // If user can publish, set state = 1 if ($model->state = 1 && $this->userCanPublish()) { $model->state = 1; } // If alias is not set, generate it if ($post['Categories']['alias'] == "") { $model->alias = $model->generateAlias($model->name); } // Genarate Json Params $params = ['categoriesImageWidth' => $post['categoriesImageWidth'], 'categoriesIntroText' => $post['categoriesIntroText'], 'categoriesFullText' => $post['categoriesFullText'], 'categoriesCreatedData' => $post['categoriesCreatedData'], 'categoriesModifiedData' => $post['categoriesModifiedData'], 'categoriesUser' => $post['categoriesUser'], 'categoriesHits' => $post['categoriesHits'], 'categoriesDebug' => $post['categoriesDebug'], 'categoryImageWidth' => $post['categoryImageWidth'], 'categoryIntroText' => $post['categoryIntroText'], 'categoryFullText' => $post['categoryFullText'], 'categoryCreatedData' => $post['categoryCreatedData'], 'categoryModifiedData' => $post['categoryModifiedData'], 'categoryUser' => $post['categoryUser'], 'categoryHits' => $post['categoryHits'], 'categoryDebug' => $post['categoryDebug'], 'itemImageWidth' => $post['itemImageWidth'], 'itemIntroText' => $post['itemIntroText'], 'itemFullText' => $post['itemFullText'], 'itemCreatedData' => $post['itemCreatedData'], 'itemModifiedData' => $post['itemModifiedData'], 'itemUser' => $post['itemUser'], 'itemHits' => $post['itemHits'], 'itemDebug' => $post['itemDebug']]; $params = $model->generateJsonParams($params); $model->params = $params; // Upload Image and Thumb if is not Null $imagePath = Yii::getAlias(Yii::$app->controller->module->categoryImagePath); $thumbPath = Yii::getAlias(Yii::$app->controller->module->categoryThumbPath); $imgNameType = Yii::$app->controller->module->imageNameType; $imgOptions = Yii::$app->controller->module->thumbOptions; $imgName = $model->name; $fileField = "image"; // Create UploadFile Instance $image = $model->uploadFile($imgName, $imgNameType, $imagePath, $fileField); if ($model->save()) { // upload only if valid uploaded file instance found if ($image !== false) { // save thumbs to thumbPaths $model->createThumbImages($image, $imagePath, $imgOptions, $thumbPath); } // Set Success Message Yii::$app->session->setFlash('success', Yii::t('articles', 'Category has been created!')); return $this->redirect(['index']); } else { // Set Error Message Yii::$app->session->setFlash('error', Yii::t('articles', 'Category could not be saved!')); return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } } else { throw new ForbiddenHttpException(); } }