/**
  * Creates a new Category model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Category();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Create new Category", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new Category", 'content' => '<span class="text-success">Create Category success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Create new Category", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->ID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #3
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', "Category <strong>{$model->title}</strong> created.");
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list']);
     } else {
         $model->status = Category::STATUS_ENABLED;
         return $this->render('create', ['model' => $model]);
     }
 }
Example #5
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $categories = Category::find()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', array('model' => $model, 'categories' => $categories));
     }
 }
 public function actionNew()
 {
     $categoryModel = new Category();
     $message = '';
     if (!empty(Yii::$app->request->post('Category'))) {
         if ($categoryModel->load(Yii::$app->request->post()) && $categoryModel->save()) {
             $message = 'Category added success';
         }
     }
     return $this->render('new', ['model' => $categoryModel, 'message' => $message]);
 }
 public function actionCreate()
 {
     $model = new Category();
     $model->user_id = Yii::$app->user->identity->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash("Category-success", Yii::t("app", "Category successfully included"));
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #8
0
 /**
  * Creates a new Category model.
  */
 public function actionCreate()
 {
     $model = new Category();
     $model->scenario = 'insert';
     if ($model->load(Yii::$app->request->post())) {
         MyModel::upload($model);
         if ($model->save() && MyModel::updateParents($model)) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
         return $this->render('create', ['model' => $model]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->parent == 0) {
             $model->saveNode();
         } elseif ($model->parent) {
             $root = Category::find($model->parent);
             $model->appendTo($root);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #10
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->parent == 0) {
             $model->saveNode();
         } else {
             if ($model->parent) {
                 $root = $this->findModel($model->parent);
                 $model->appendTo($root);
             }
         }
         return $this->render('tree');
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('categoryCreate')) {
         $model = new Category();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
Example #12
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can("category/create")) {
         $model = new Category();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             if ($model->parent == NULL) {
                 $model->parent = 0;
                 $model->save();
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         $this->redirect('/');
     }
 }
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $category_array = Category::getAllCategories();
     if ($category_array) {
         $category_array = ['0' => '顶级分类'] + $category_array;
     } else {
         $category_array = ['0' => '顶级分类'];
     }
     if (isset($category_array[1]) && $category_array[1] == '未分类') {
         unset($category_array[1]);
     }
     if ($model->load($_POST)) {
         if ($model->save()) {
             $this->redirect(['category/view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model, 'category_array' => $category_array]);
 }
Example #14
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post())) {
         $model->url = UrlHelp::translateUrl($model->name);
         if ($model->validate()) {
             $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
             if ($model->imageFile) {
                 if ($imgName = $model->upload($model->url)) {
                     $model->img = $imgName;
                 }
             }
             $model->imageFile = null;
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (isset($_POST['name']) && is_array($_POST['name'])) {
             foreach ($_POST['name'] as $lang => $val) {
                 $model->setName($lang, $val);
             }
         }
         if (isset($_POST['content']) && is_array($_POST['content'])) {
             foreach ($_POST['content'] as $lang => $val) {
                 $model->setContent($lang, $val);
             }
         }
         $model->updateURLCode();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #16
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $t = Yii::$app->request->get('t');
     switch ($t) {
         case 'income':
             $model->type = 0;
             break;
         case 'expense':
             $model->type = 1;
             break;
         default:
             $model->type = 1;
             $t = 'expense';
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['operation/create', 't' => $t]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #17
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     // echo Yii::$app->request->baseUrl;die;
     //echo Yii::$app->homeUrl;die;
     if ($model->load(Yii::$app->request->post())) {
         $model->files = UploadedFile::getInstance($model, 'logo');
         if ($logo_path = $model->upload()) {
             $model->logo = $logo_path;
         }
         $model->addtime = time();
         $model->goCategory($model);
         $model->save(false);
         return $this->redirect(['view', 'id' => (string) $model->_id]);
     } else {
         $category = $model->getCategory();
         $category_info = array();
         foreach ($category as $val) {
             $category_info["{$val->_id}"] = $val->cate_name;
         }
         return $this->render('create', ['model' => $model, 'category' => $category_info]);
     }
 }
Example #18
0
 public function actionCategory()
 {
     $category = new Category();
     if ($category->load(Yii::$app->request->post()) && $category->save()) {
         return $this->goHome();
     } else {
         return $this->render('category', ['category' => $category]);
     }
 }