當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Category::load方法代碼示例

本文整理匯總了PHP中common\models\Category::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::load方法的具體用法?PHP Category::load怎麽用?PHP Category::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\Category的用法示例。


在下文中一共展示了Category::load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate

 /**
  * 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();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:RubenDjOn,項目名稱:originofthememes,代碼行數:20,代碼來源:CategoryController.php

示例2: actionCreate

 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($module)
 {
     $model = new Category();
     $model['module'] = $module;
     $parents = [];
     $root = Category::findOne(['parent_id' => null, 'title' => $module, 'module' => $module]);
     if (empty($root)) {
         throw new NotFoundHttpException('Module không tồn tại');
     }
     $parents = $root->children()->all();
     $parent_id = $this->buildTree($parents);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $parent_id = $model['parent_id'];
         $model['slug'] = $this->slugAlias($model);
         if (empty($parent_id)) {
             $model->appendTo($root);
         } else {
             $parent = Category::findOne(['id' => $parent_id, 'module' => $module]);
             $model->appendTo($parent);
         }
         if ($model->save()) {
             return $this->redirect(['index', 'module' => $module]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'module' => $module, 'parent_id' => $parent_id]);
     }
 }
開發者ID:nguyentuansieu,項目名稱:phutungoto,代碼行數:32,代碼來源:CategoryController.php

示例3: actionCreate

 /**
  * 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->category_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:pldolot,項目名稱:apc-quality-cn131df131ss132-06,代碼行數:14,代碼來源:CategoryController.php

示例4: insert

 public function insert(CategoryDto $categoryDto)
 {
     $category = new Category();
     if ($category->load(['Category' => ArrayHelper::toArray($categoryDto)])) {
         $category->insert();
         return ArrayHelper::toArray($category, ['common\\models\\Category' => $categoryDto->activeAttributes()]);
     } else {
         return [];
     }
 }
開發者ID:xiaomige,項目名稱:giishop,代碼行數:10,代碼來源:CategoryServiceImpl.php

示例5: actionCreate

 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param int $id id of the parent category
  * @return mixed
  */
 public function actionCreate($id = null)
 {
     $categories = Category::find()->all();
     $model = new Category();
     $model->parent_id = $id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories]);
     }
 }
開發者ID:Krinnerion,項目名稱:shop,代碼行數:17,代碼來源:CategoryController.php

示例6: actionCreate

 /**
  * 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('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Category();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:James88,項目名稱:www.yubin.com,代碼行數:16,代碼來源:CategoryController.php

示例7: actionCreate

 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the main 'index' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $model->scenario = 'create';
     $dataProvider = new ActiveDataProvider(['query' => Category::find()]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('message', 'The category has been created successfully.');
         return $this->redirect('index', ['dataProvider' => $dataProvider]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:BorisMatonickin,項目名稱:yiicms,代碼行數:17,代碼來源:CategoryController.php

示例8: actionCreatecategory

 public function actionCreatecategory()
 {
     $category = new Category();
     $data = \Yii::$app->request->post("Category");
     if (!empty($data)) {
         $category->load(\Yii::$app->request->post());
     }
     if (!empty($data) && $category->validate() && $category->save()) {
         return $this->render('success_create_category');
     }
     return $this->render('category_edit', ['category' => $category, 'parents' => Category::getList()]);
 }
開發者ID:BoBRoID,項目名稱:plochadka,代碼行數:12,代碼來源:SiteController.php

示例9: actionInsertCat

 /**
  * Экшен '/admin/catalog/insert-cat' - добавление категории
  * Экшен нельзя задать с помощью CRUD т.к. в 'nested sets' переопределяется метод 'insert'
  * @return string
  * @throws InvalidParamException
  */
 public function actionInsertCat()
 {
     $category = new Category();
     $category->scenario = 'insert';
     if ($category->load(Yii::$app->request->post())) {
         // Валидируем модель
         if ($category->validate()) {
             $parent = Category::findOne($category->parent);
             $this->afterSaveCategory($category->appendTo($parent));
         }
     }
     return $this->render('update-cat', ['model' => $category]);
 }
開發者ID:andreykluev,項目名稱:yii2-catalog-module,代碼行數:19,代碼來源:AdminController.php

示例10: actionAdd

 public function actionAdd()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '成功添加分類“' . $model->name . '”。');
             return $this->redirect(['index']);
         } else {
             Yii::$app->session->setFlash('danger', '分類添加失敗。');
         }
     }
     return $this->render('form', ['model' => $model]);
 }
開發者ID:daixianceng,項目名稱:xiaoego.com,代碼行數:13,代碼來源:CategoryController.php

示例11: actionCreate

 /**
  * Creates a new Meta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($parent = 0)
 {
     $model = new Category();
     $model->parent = intval($parent);
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:Penton,項目名稱:MoBlog,代碼行數:18,代碼來源:CategoryController.php

示例12: actionCreate

 public function actionCreate()
 {
     $model = new Category();
     if (isset($_POST['sbm_create_category'])) {
         $model->load($_POST);
         //отправляем массив на парсинг
         var_dump($model);
         die;
         //$model->save();
     } else {
         $model = Category::findAll("where parent_id is NULL");
         //выбор коневых категорий
         $this->render('create', ['model' => $model]);
     }
 }
開發者ID:kunaksergey,項目名稱:shop,代碼行數:15,代碼來源:CategoryController.php

示例13: actionCreate

 /**
  * 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 (!isset($model->parentId)) {
             $result = $model->saveNode();
         } else {
             $parent = Category::findOne($model->parentId);
             $result = $model->appendTo($parent);
         }
         if ($result) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:hichamuradess,項目名稱:yii2-shopper,代碼行數:21,代碼來源:CategoryController.php

示例14: actionCreate

 /**
  * 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())) {
         $parent = Category::findOne($model->parent_id);
         if (!empty($parent)) {
             $model->indent = $parent->indent + 1;
         } else {
             $model->indent = 0;
         }
         $model->save();
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:huynhtuvinh87,項目名稱:cms,代碼行數:21,代碼來源:CategoryController.php

示例15: actionIndex

 public function actionIndex()
 {
     if (Yii::$app->request->get('id')) {
         $model = Category::findOne(Yii::$app->request->get('id'));
     } else {
         $model = new Category();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash("success", "Update Category Successful");
             return $this->refresh();
         }
     }
     $items = Category::find()->where(['parent_id' => null])->all();
     return $this->render("index", ['model' => $model, 'items' => $items]);
 }
開發者ID:Mitonios,項目名稱:mitonios-blog,代碼行數:16,代碼來源:CategoryController.php


注:本文中的common\models\Category::load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。