当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::find方法代码示例

本文整理汇总了PHP中common\models\Category::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::find方法的具体用法?PHP Category::find怎么用?PHP Category::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Category的用法示例。


在下文中一共展示了Category::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionIndex

 /**
  * Lists all Category models.
  * @return mixed
  */
 public function actionIndex()
 {
     //if(!Yii::$app->user->can('viewYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $searchModel = new CategorySearch();
     $dataProvider = Category::get(0, Category::find()->asArray()->all());
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
开发者ID:James88,项目名称:www.yubin.com,代码行数:11,代码来源:CategoryController.php

示例2: actionView

 public function actionView($id)
 {
     if ($id <= 0) {
         $this->goHome();
     }
     $allCategory = Category::find()->asArray()->all();
     $arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
     $arrSubCat = Category::getArraySubCatalogId($id, $allCategory);
     /****** 价格筛选 ****/
     $result = (new Query())->select('min(price) as min, max(price) as max')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->one();
     $min = $result['min'];
     $max = $result['max'];
     if ($max > $min && $max > 0) {
         // 计算跨度
         $priceGrade = 0.0001;
         for ($i = -2; $i < log10($max); $i++) {
             $priceGrade *= 10;
         }
         $span = ceil(($max - $min) / 5 / $priceGrade) * $priceGrade;
         if ($span == 0) {
             $span = $priceGrade;
         }
         // 计算价格的起点和终点
         for ($i = 1; $min > $span * $i; $i++) {
         }
         for ($j = 1; $min > $span * ($i - 1) + $priceGrade * $j; $j++) {
         }
         $priceFilter['start'] = $span * ($i - 1) + $priceGrade * ($j - 1);
         for (; $max >= $span * $i; $i++) {
         }
         $priceFilter['end'] = $span * $i + $priceGrade * ($j - 1);
         $priceFilter['span'] = $span;
     }
     /****** 价格筛选 end ****/
     /****** 品牌筛选 start ****/
     $result = (new Query())->select('distinct(brand_id)')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->all();
     $ids = ArrayHelper::map($result, 'brand_id', 'brand_id');
     $brandFilter = Brand::find()->where(['id' => $ids])->orderBy(['name' => SORT_ASC])->all();
     /****** 品牌筛选 end ****/
     $query = Product::find()->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE]);
     // 如果选择了价格区间
     if (Yii::$app->request->get('max')) {
         $min = intval(Yii::$app->request->get('min'));
         $max = intval(Yii::$app->request->get('max'));
         if ($min >= 0 && $max) {
             $query->andWhere(['and', ['>', 'price', $min], ['<=', 'price', $max]]);
         }
     }
     // 如果选择了品牌
     if (Yii::$app->request->get('brand_id')) {
         $brandId = intval(Yii::$app->request->get('brand_id'));
         if ($brandId >= 0) {
             $query->andWhere(['brand_id' => $brandId]);
         }
     }
     // 侧边热销商品
     $sameCategoryProducts = Product::find()->where(['category_id' => $id])->orderBy(['sales' => SORT_DESC])->limit(5)->all();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $this->render('view', ['model' => $this->findModel($id), 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'priceFilter' => isset($priceFilter) ? $priceFilter : null, 'brandFilter' => $brandFilter, 'sameCategoryProducts' => $sameCategoryProducts]);
 }
开发者ID:CTaiDeng,项目名称:funshop,代码行数:60,代码来源:CategoryController.php

示例3: 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

示例4: 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

示例5: 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

示例6: 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 ($id !== null && ($model = Category::find($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:jackycgq,项目名称:forum-advanced,代码行数:15,代码来源:CategoryController.php

示例7: actionIndex

 /**
  * 概要
  * @return string
  */
 public function actionIndex()
 {
     $recentPublishedPost = Post::find()->selectNoText()->recentPublished()->all();
     $postCount = Post::find()->published()->count();
     $categoryCount = Category::find()->count();
     //todo: 评论数量 最新回复
     return $this->render('index', ['recentPublishedPost' => $recentPublishedPost, 'postCount' => $postCount, 'categoryCount' => $categoryCount]);
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:12,代码来源:SiteController.php

示例8: init

 public function init()
 {
     parent::init();
     foreach (Category::find()->all() as $category) {
         $this->_catagories[$category->parent_id][] = $category;
     }
     //print_r($this->_catagories);die;
 }
开发者ID:phpsong,项目名称:ExtJS5-Yii2,代码行数:8,代码来源:Categories.php

示例9: getCategoryObject

 public function getCategoryObject()
 {
     if (!empty($this->_category)) {
         return $this->_category;
     }
     $category = Category::find()->where(['id' => $this->category])->one();
     return $this->_category = $category;
 }
开发者ID:BoBRoID,项目名称:plochadka,代码行数:8,代码来源:Post.php

示例10: actionCreate

 /**
  * Action method for creating a new forum topic.
  * @return string|Response action method execution result.
  */
 public function actionCreate()
 {
     $topic = new Topic();
     if ($topic->load(Yii::$app->request->post()) && $topic->save()) {
         return $this->redirect($topic->url);
     }
     return $this->render('create', ['topic' => $topic, 'categories' => Category::find()->all(), 'sections' => empty($topic->category_id) ? [] : Section::findAll(['category_id' => $topic->category_id])]);
 }
开发者ID:keltstr,项目名称:yii2-forum-1,代码行数:12,代码来源:TopicController.php

示例11: 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

示例12: findModel

 /**
  * Finds the Meta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::find()->andWhere('mid=:mid', [':mid' => $id])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:15,代码来源:CategoryController.php

示例13: getNews

 public static function getNews($cid, $num)
 {
     $allCategory = Category::find()->asArray()->all();
     $arrayCategoryIdName = \yii\helpers\ArrayHelper::map($allCategory, 'id', 'name');
     $arrSubCat = Category::getArraySubCatalogId($cid, $allCategory);
     $where = ['and', ['category_id' => $arrSubCat], 'status>=' . Status::STATUS_ACTIVE];
     $news = News::find()->where($where)->limit($num)->all();
     return $news;
 }
开发者ID:pear2007,项目名称:www.yii2.com,代码行数:9,代码来源:News.php

示例14: actionUpdate

 /**
  * Редактирование поста.
  * @param string $id идентификатор редактируемого поста
  * @return string|Response
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'authors' => User::find()->all(), 'tags' => Tags::find()->all(), 'category' => Category::find()->all()]);
     }
 }
开发者ID:richardcj,项目名称:Blog-Yii2,代码行数:14,代码来源:PostController.php

示例15: getToSelect

 /**
  * Получить массив названий категорий с их ID.
  * @return array
  */
 public static function getToSelect()
 {
     $result = [];
     $categories = Category::find()->where(['[[status]]' => true])->orderBy('[[created_at]] ASC')->all();
     if (!empty($categories)) {
         $result = ArrayHelper::map($categories, 'id', 'name');
     }
     return $result;
 }
开发者ID:dmdropkick,项目名称:shop,代码行数:13,代码来源:Category.php


注:本文中的common\models\Category::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。