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


PHP Category::getByParentId方法代码示例

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


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

示例1: recursiveGetTree

 private function recursiveGetTree($model, $allowed_category_ids)
 {
     $params = [$this->route];
     $params += $this->current_selections;
     $params['category_group_id'] = $this->category_group_id;
     $params['last_category_id'] = $model->id;
     if (!isset($params['categories'])) {
         $params['categories'] = [];
     }
     $active = false;
     if (isset($this->current_selections['last_category_id'])) {
         $active = $this->current_selections['last_category_id'] == $model->id;
     }
     $result = ['label' => $model->name, 'url' => Url::to($params), 'items' => [], 'active' => in_array($model->id, $params['categories']) || $active, '_model' => &$model];
     if ($this->recursive === true) {
         $children = Category::getByParentId($model->id);
         foreach ($children as $child) {
             if ($this->onlyAvailableProducts === true && !in_array($child->id, $allowed_category_ids)) {
                 continue;
             }
             $result['items'][] = $this->recursiveGetTree($child, $allowed_category_ids);
         }
     }
     return $result;
 }
开发者ID:heartshare,项目名称:dotplant2,代码行数:25,代码来源:CategoriesWidget.php

示例2: run

 /**
  * @inheritdoc
  * @return string
  */
 public function run()
 {
     $cacheKey = "PlainCategoriesWidget:" . $this->root_category_id . ":" . $this->viewFile;
     $result = Yii::$app->cache->get($cacheKey);
     if ($result === false) {
         $categories = Category::getByParentId($this->root_category_id);
         $result = $this->render($this->viewFile, ['categories' => $categories]);
         Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::className())]));
     }
     return $result;
 }
开发者ID:Razzwan,项目名称:dotplant2,代码行数:15,代码来源:PlainCategoriesWidget.php


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