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


PHP Category::parent方法代碼示例

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


在下文中一共展示了Category::parent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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()
 {
     if (!$this->is_access('category/create')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // 加入分類推薦
         $CatRecommend = new CatRecommend();
         $CatRecommend->insertRecommend($model->cat_id, $_POST['Category']['recommend_type']);
         // 是否需要顯示在導航欄
         if ($model->show_in_nav == 1) {
             $Nav = new Nav();
             $Nav->addData('c', $model->cat_id);
         }
         Yii::$app->session->setFlash('success', '添加成功');
         return $this->redirect(['index']);
     } else {
         Yii::$app->view->params['meta_title'] = '添加分類';
         $catList = $model->parent(0);
         return $this->render('create', ['model' => $model, 'catList' => $catList]);
     }
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:29,代碼來源:CategoryController.php

示例2: actionUpdate

 /**
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('goods/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     $GoodsGallery = new GoodsGallery();
     $post = Yii::$app->request->post();
     if ($model->load($post)) {
         $GoodsGallery->load($post);
         if ($model->validate() && $GoodsGallery->validate()) {
             // 商品封麵圖片
             if ($_FILES['Goods']['error']['goods_img'] === 0) {
                 $model->goods_img = File::uploadImage($model, 'goods_img', 'shop');
                 $model->goods_thumb = Images::thumb('./' . $model->goods_img, 250, 250);
             }
             if ($model->save(false)) {
                 // 商品相冊
                 if ($_FILES['GoodsGallery']['error']['img_url'][0] === 0) {
                     $img_url = File::uploadImages($GoodsGallery, 'img_url', 'goods');
                     $GoodsGallery->addData($model->goods_id, $img_url);
                 }
                 // 商品屬性
                 GoodsAttr::addData($model->goods_id);
             }
             Yii::$app->session->setFlash('success', '編輯成功');
         }
         return $this->redirect(['index']);
     } else {
         // 商品分類
         $Category = new Category();
         $categoryList = $Category->parent(0, false);
         // 品牌
         $Brand = new Brand();
         $brandList = $Brand->getLists();
         // 商品類型
         $GoodsType = new GoodsType();
         $goodsTypeList = $GoodsType->dropList();
         // 相冊
         $goodsGalleryList = $GoodsGallery->getGoodsGallery($id);
         Yii::$app->view->params['meta_title'] = '編輯商品';
         return $this->render('update', ['model' => $model, 'GoodsGallery' => $GoodsGallery, 'categoryList' => $categoryList, 'brandList' => $brandList, 'goodsTypeList' => $goodsTypeList, 'goodsGalleryList' => $goodsGalleryList]);
     }
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:49,代碼來源:GoodsController.php


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