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


PHP models\Category類代碼示例

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


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

示例1: actionView

 /**
  * Просмотр списка постов по тегу
  * @param $id
  * @return string
  */
 public function actionView($id)
 {
     $tagModel = new Tags();
     $tag = $tagModel->getTag($id);
     $categoryModel = new Category();
     return $this->render('view', ['tag' => $tag, 'posts' => $tag->getTagPosts(), 'categories' => $categoryModel->getCategories()]);
 }
開發者ID:sydorenkovd,項目名稱:test-items,代碼行數:12,代碼來源:TagController.php

示例2: actionLoadGoods

 public function actionLoadGoods($id, $category = 'all', $q = '')
 {
     $offset = (int) Yii::$app->request->post('offset');
     Yii::$app->response->format = Response::FORMAT_JSON;
     /* @var $model Store */
     $model = Store::findOne(['id' => $id, 'status' => [Store::STATUS_ACTIVE, Store::STATUS_REST]]);
     if (!$model) {
         throw new NotFoundHttpException('未找到該營業點!');
     }
     if ($q !== '') {
         $query = $model->getGoods()->andWhere(['or', ['like', 'name', $q], ['like', 'description', $q]]);
     } else {
         $modelCate = $category === 'all' ? null : Category::findOne(['slug' => $category]);
         if ($modelCate) {
             $query = $model->getGoods($modelCate->id);
         } else {
             $query = $model->getGoods();
         }
     }
     $limit = 8;
     $goodsList = $query->offset($offset)->limit($limit)->all();
     $output = ['status' => 'ok', 'html' => '', 'length' => count($goodsList)];
     $output['end'] = $output['length'] < $limit;
     foreach ($goodsList as $goods) {
         $output['html'] .= $this->renderPartial('_item', ['goods' => $goods, 'lazy' => false]);
     }
     return $output;
 }
開發者ID:shunzi250,項目名稱:xiaoego.com,代碼行數:28,代碼來源:StoreController.php

示例3: insertCategories

 public function insertCategories($categoryIds, $beforeCount = true, $afterCount = true)
 {
     if (!is_array($categoryIds)) {
         return false;
     }
     $categoryIds = array_unique($categoryIds);
     $this->deleteCategories($beforeCount);
     //先刪除文章分類
     //插入新分類
     if ($categoryIds) {
         foreach ($categoryIds as $v) {
             if (!Category::find()->andWhere('mid=:mid', [':mid' => $v])->one()) {
                 continue;
             }
             $model = new Relationship();
             $model->cid = $this->cid;
             $model->mid = $v;
             $model->insert(false);
             if ($afterCount) {
                 //更新分類文章數
                 Category::updateAllCounters(['count' => 1], ['mid' => $v]);
             }
         }
     }
     return true;
 }
開發者ID:Penton,項目名稱:MoBlog,代碼行數:26,代碼來源:Post.php

示例4: actionCategory

 public function actionCategory($id)
 {
     $backUrl = \Yii::$app->request->referrer;
     $category = Category::findOne($id);
     $this->layout = 'basic-category';
     return $this->render('category', compact('category', 'backUrl'));
 }
開發者ID:czechcamus,項目名稱:dasport,代碼行數:7,代碼來源:SiteController.php

示例5: actionIndex

 public function actionIndex($slug)
 {
     $query = Vidmage::find()->joinWith('vidmageCategories.category')->where(['category.slug' => $slug])->orderBy(['id' => SORT_DESC]);
     $vidmages = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $channel = Category::findOne(['slug' => $slug]);
     return $this->render('index', compact('vidmages', 'channel'));
 }
開發者ID:RubenDjOn,項目名稱:originofthememes,代碼行數:7,代碼來源:CategoryController.php

示例6: actionDetail

 public function actionDetail($id)
 {
     /* @var $model Store */
     $model = Store::findOne($id);
     if (!$model) {
         throw new BadRequestHttpException('未找到該營業點!');
     }
     if ($model->status === Store::STATUS_DISABLED) {
         throw new BadRequestHttpException('該店鋪已被禁用,請重新選擇!');
     }
     $data['store'] = $model->toArray(['id', 'name', 'school_id', 'address', 'cellphone', 'telephone', 'notice', 'status', 'hours', 'has_book', 'has_down', 'has_gift', 'has_least', 'down_upper', 'down_val', 'gift_upper', 'gift_val', 'least_val', 'created_at']);
     $data['store']['downMsg'] = $model->downMsg;
     $data['store']['giftMsg'] = $model->giftMsg;
     $data['categories'] = Category::getKeyValuePairs();
     foreach ($data['categories'] as $key => $name) {
         $goodsList = $model->getGoods($key)->all();
         if ($goodsList) {
             foreach ($goodsList as $goods) {
                 $goodsArr = $goods->toArray();
                 $data['goodsList'][$key][] = $goodsArr;
             }
         } else {
             $data['goodsList'][$key] = [];
         }
     }
     return $data;
 }
開發者ID:daixianceng,項目名稱:xiaoego.com,代碼行數:27,代碼來源:StoreController.php

示例7: addData

 /**
  * 其他分類需要顯示在導航欄的新增方法
  * @param string $ctype 其他分類表標識 a:文章分類表,c:商品分類表
  * @param int $cid 其他表分類id
  * @return mixed
  */
 public function addData($ctype, $cid)
 {
     // 如果已經存在就不繼續執行了
     if ($this->find()->where(['ctype' => $ctype, 'cid' => $cid])->one()) {
         return true;
     }
     switch ($ctype) {
         case 'a':
             // 文章分類
             $this->name = ArticleCat::findOne($cid)->cat_name;
             $this->url = '';
             // 前台還沒有做,暫時空起
             break;
         case 'c':
             // 商品分類
             $this->name = Category::findOne($cid)->cat_name;
             $this->url = '';
             // 前台還沒有做,暫時空起
             break;
         default:
             return false;
     }
     $this->ctype = $ctype;
     $this->cid = $cid;
     $this->type = 'middle';
     if ($this->insert(false)) {
         return true;
     }
     return false;
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:36,代碼來源:Nav.php

示例8: beforeSave

 public function beforeSave($insert)
 {
     $redirectLink = new Redirect(['from' => $this->fullLink]);
     if (!$this->link) {
         $this->link = TranslitHelper::to($this->title);
     }
     if ($this->isAttributeChanged('parent') || $this->isAttributeChanged('link')) {
         $this->fullLink = '';
         if ($parent = $this->getParentCategory()) {
             $linkParts = [$parent->link];
             while ($parent = $parent->getParentCategory()) {
                 $linkParts[] = $parent->getRelativeLink();
             }
             $this->fullLink = implode('/', $linkParts) . '/';
         }
         $this->fullLink .= $this->link;
         if ($childs = $this->getChildCategories()) {
             foreach ($childs as $childCategory) {
                 $childCategory->fullLink = $this->fullLink . '/' . $childCategory->link;
                 $childCategory->save(false);
             }
         }
         $redirectLink->to = $this->fullLink;
     }
     if ($redirectLink->to) {
         $redirectLink->save();
     }
     return parent::beforeSave($insert);
     // TODO: Change the autogenerated stub
 }
開發者ID:BoBRoID,項目名稱:new.k-z,代碼行數:30,代碼來源:Category.php

示例9: actionView

 public function actionView($id)
 {
     $model = $this->findModel($id);
     $allCategory = Category::find()->asArray()->all();
     $arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
     $rootCategoryId = Category::getRootCatalogId($model->category_id, $allCategory);
     $arraySameRootCategory = Category::getArraySubCatalogId($rootCategoryId, $allCategory);
     // 同類商品  和 同大類商品
     $sameCategoryProducts = Product::find()->where(['category_id' => $model->category_id])->orderBy(['sales' => SORT_DESC])->limit(3)->all();
     $sameRootCategoryProducts = Product::find()->where(['category_id' => $arraySameRootCategory])->orderBy(['sales' => SORT_DESC])->limit(Yii::$app->params['productHotCount'])->all();
     // 記錄瀏覽日誌
     $historyProducts = [];
     $cookies = Yii::$app->request->cookies;
     if ($cookies->has('productHistory')) {
         $arrHistory = explode(',', $cookies->getValue('productHistory'));
         foreach ($arrHistory as $id) {
             $product = Product::findOne($id);
             if ($product) {
                 array_push($historyProducts, $product);
             }
         }
         array_unshift($arrHistory, $id);
         $arrHistory = array_unique($arrHistory);
         while (count($arrHistory) > Yii::$app->params['productHistoryCount']) {
             array_pop($arrHistory);
         }
         Yii::$app->response->cookies->remove('productHistory');
         Yii::$app->response->cookies->add(new Cookie(['name' => 'productHistory', 'value' => implode(',', $arrHistory), 'expire' => time() + 3600 * 24 * 30]));
     } else {
         Yii::$app->response->cookies->add(new Cookie(['name' => 'productHistory', 'value' => $id, 'expire' => time() + 3600 * 24 * 30]));
     }
     return $this->render('view', ['model' => $model, 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'sameCategoryProducts' => $sameCategoryProducts, 'sameRootCategoryProducts' => $sameRootCategoryProducts, 'historyProducts' => $historyProducts]);
 }
開發者ID:CTaiDeng,項目名稱:funshop,代碼行數:33,代碼來源:ProductController.php

示例10: getProductByCategory

 public static function getProductByCategory($category_id, $limit = 6)
 {
     $category = new Category();
     $product = new Product();
     $categoriesData = $category->findAll(['parent_id' => $category_id]);
     $categoryIDs = [];
     if ($categoriesData) {
         foreach ($categoriesData as $categoryData) {
             $categoryIDs[] = $categoryData->id;
         }
         $products = $product->find()->where(['status' => 10, 'is_featured' => 10])->andWhere(['in', 'category_id', $categoryIDs])->limit($limit)->all();
     } else {
         $products = $product->find()->where(['status' => 10, 'is_front' => 10, 'category_id' => $category_id])->limit($limit)->all();
     }
     return $products;
 }
開發者ID:nguyentuansieu,項目名稱:phutungoto,代碼行數:16,代碼來源:FrontendController.php

示例11: search

 public function search($params)
 {
     $query = Category::find()->where(['status' => Category::STATUS_DISPLAY]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->name) {
         $query->andFilterWhere(['like', 'name', $this->name]);
     }
     if ($this->slug) {
         $query->andFilterWhere(['like', 'slug', $this->slug]);
     }
     if ($this->parent) {
         $category = Category::find()->where(['like', 'name', $this->parent])->all();
         if ($category) {
             $c_ids = [];
             foreach ($category as $v) {
                 $c_ids[] = $v->id;
             }
             $query->andFilterWhere(['in', 'parent', $c_ids]);
         } else {
             $query->andFilterWhere(['in', 'id', [0]]);
         }
     }
     return $dataProvider;
 }
開發者ID:specialnote,項目名稱:myYii,代碼行數:27,代碼來源:CategorySearch.php

示例12: findById

 protected function findById($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('請求頁麵不存在');
     }
 }
開發者ID:xiaomige,項目名稱:giishop,代碼行數:8,代碼來源:CategoryServiceImpl.php

示例13: findModel

 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
開發者ID:BorisMatonickin,項目名稱:yiicms,代碼行數:15,代碼來源:CategoryController.php

示例14: getCategoryList

 /**
  * Возвращает список возможных категорий товара.
  * Примечание: используется в backend/user/index представлении.
  *
  * @return mixed
  */
 public static function getCategoryList()
 {
     $categories = [];
     foreach (Category::getCategory() as $item_name) {
         $categories[$item_name->id] = $item_name->name;
     }
     return $categories;
 }
開發者ID:baranov-nt,項目名稱:some-2,代碼行數:14,代碼來源:ProductSearch.php

示例15: actionIndex

 public function actionIndex($c_url)
 {
     $model = Category::find()->with(['activeSubcategories'])->byUrl($c_url)->active()->one();
     if ($model === null) {
         throw new NotFoundHttpException();
     }
     return $this->render('index', ['model' => $model]);
 }
開發者ID:ninetor,項目名稱:yii-classifield,代碼行數:8,代碼來源:CategoriesController.php


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