当前位置: 首页>>代码示例>>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;未经允许,请勿转载。