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


PHP models\Category类代码示例

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


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

示例1: actionIndex

 public function actionIndex($category_id = null)
 {
     $searchModel = new Category();
     $searchModel->active = 1;
     $params = Yii::$app->request->get();
     $dataProvider = $searchModel->search($params);
     $selectedCategory = null;
     if ($category_id !== null) {
         $selectedCategory = Category::findById($category_id);
     }
     if ($selectedCategory !== null) {
         if (Yii::$app->request->isPost === true) {
             $newProperty = isset($_GET['add_property_id']) ? Property::findById($_GET['add_property_id']) : null;
             if ($newProperty !== null) {
                 $filterSet = new FilterSets();
                 $filterSet->category_id = $selectedCategory->id;
                 $filterSet->property_id = $newProperty->id;
                 $filterSet->sort_order = 65535;
                 $filterSet->save();
             }
         }
     }
     $groups = PropertyGroup::getForObjectId(Object::getForClass(Product::className())->id, false);
     $propertiesDropdownItems = [];
     foreach ($groups as $group) {
         $item = ['label' => $group->name, 'url' => '#', 'items' => []];
         $properties = Property::getForGroupId($group->id);
         foreach ($properties as $prop) {
             $item['items'][] = ['label' => $prop->name, 'url' => '?category_id=' . $category_id . '&add_property_id=' . $prop->id, 'linkOptions' => ['class' => 'add-property-to-filter-set', 'data-property-id' => $prop->id, 'data-action' => 'post']];
         }
         $propertiesDropdownItems[] = $item;
     }
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'selectedCategory' => $selectedCategory, 'propertiesDropdownItems' => $propertiesDropdownItems]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:34,代码来源:FilterSetsController.php

示例2: createCategory

 private function createCategory($name, $parent_id)
 {
     $model = new Category();
     $model->loadDefaultValues();
     $model->name = $name;
     $model->parent_id = $parent_id;
     $model->slug = Helper::createSlug($model->name);
     $model->save();
     return $model;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:10,代码来源:DemoDataController.php

示例3: appendPart

 /**
  * @inheritdoc
  */
 public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
 {
     /*
         В parameters должен храниться last_category_id
         Если его нет - используем parameters.category_id
     */
     $category_id = null;
     if (isset($parameters['last_category_id'])) {
         $category_id = $parameters['last_category_id'];
     } elseif (isset($parameters['category_id'])) {
         $category_id = $parameters['category_id'];
     }
     $used_params[] = 'last_category_id';
     $used_params[] = 'category_id';
     if ($category_id === null) {
         return false;
     }
     $category = Category::findById($category_id);
     if (is_object($category) === true) {
         $parentIds = $category->getParentIds();
         foreach ($parentIds as $id) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
         }
         $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category_id);
         return $category->getUrlPath($this->include_root_category);
     } else {
         return false;
     }
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:32,代码来源:PartialCategoryPathPart.php

示例4: getParent

 /**
  * @return ActiveRecord
  */
 public function getParent()
 {
     $cacheKey = 'TreeParent:' . $this->owner->className() . ':' . $this->owner->getAttribute($this->idAttribute);
     /** @var $parent ActiveRecord */
     $parent = Yii::$app->cache->get($cacheKey);
     if ($parent === false) {
         $className = $this->owner->className();
         $parent = new $className();
         $parent_id = $this->owner->getAttribute($this->parentIdAttribute);
         if ($parent_id < 1) {
             return null;
         }
         /* findById does not have a calling standard and uses different parameters. For example isActive = 1.
          * But we must get a parent model by primary id only.
          * Uncomment this code if you unify findById method.
          */
         // if ($parent->hasMethod('findById')) {
         //     $parent = $parent->findById($parent_id);
         // } else {
         if ($parent instanceof Category) {
             $parent = Category::findById($parent_id, null);
         } else {
             $parent = $parent->findOne($parent_id);
         }
         Yii::$app->cache->set($cacheKey, $parent, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag($className)]]));
     }
     return $parent;
 }
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:31,代码来源:Tree.php

示例5: run

 public function run()
 {
     $query = Category::find();
     $query->andWhere([Category::tableName() . '.active' => 1]);
     if ($this->root_category_id !== null) {
         $query->andWhere([Category::tableName() . '.parent_id' => $this->root_category_id]);
     }
     if ($this->category_group_id !== null) {
         $query->andWhere([Category::tableName() . '.category_group_id' => $this->category_group_id]);
     }
     $query->groupBy(Category::tableName() . ".id");
     $query->orderBy($this->sort);
     if ($this->limit !== null) {
         $query->limit($this->limit);
     }
     $object = Object::getForClass(Category::className());
     \app\properties\PropertiesHelper::appendPropertiesFilters($object, $query, $this->values_by_property_id, []);
     $sql = $query->createCommand()->getRawSql();
     $cacheKey = "FilteredCategoriesWidget:" . md5($sql);
     $result = Yii::$app->cache->get($cacheKey);
     if ($result === false) {
         $categories = Category::findBySql($sql)->all();
         $result = $this->render($this->viewFile, ['categories' => $categories]);
         Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::tableName())]));
     }
     return $result;
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:27,代码来源:FilteredCategoriesWidget.php

示例6: getLinks

 protected function getLinks()
 {
     if (!is_null($this->frontendLink) || !is_null($this->backendLink)) {
         return true;
     }
     /** @var Image $image */
     $image = Image::findById($this->img_id);
     if (is_null($image) || is_null($object = Object::findById($image->object_id))) {
         return false;
     }
     /** @var \app\models\Object $object */
     switch ($object->object_class) {
         case Page::className():
             $this->getPageLinks($image->object_model_id);
             break;
         case Category::className():
             $this->getCategoryLinks($image->object_model_id);
             break;
         case Product::className():
             $this->getProductLinks($image->object_model_id);
             break;
         default:
             return false;
     }
     return true;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:26,代码来源:ErrorImage.php

示例7: up

 public function up()
 {
     $this->addColumn(Page::tableName(), 'mate_keywords', $this->string()->defaultValue(null));
     $this->addColumn(Product::tableName(), 'mate_keywords', $this->string()->defaultValue(null));
     $this->addColumn(Category::tableName(), 'mate_keywords', $this->string()->defaultValue(null));
     $this->addColumn(PrefilteredPages::tableName(), 'mate_keywords', $this->string()->defaultValue(null));
 }
开发者ID:HannibalLecktor,项目名称:dotplant2,代码行数:7,代码来源:m160107_092054_add_meta_keywords_1.php

示例8: down

 public function down()
 {
     $this->dropColumn(Category::tableName(), 'date_added');
     $this->dropColumn(Category::tableName(), 'date_modified');
     $this->dropColumn(Product::tableName(), 'date_added');
     $this->dropColumn(Product::tableName(), 'date_modified');
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:7,代码来源:m150923_101638_date_modified.php

示例9: run

 /**
  * @return string
  */
 public function run()
 {
     parent::run();
     if (null === $this->rootCategory) {
         return '';
     }
     $cacheKey = $this->className() . ':' . implode('_', [$this->viewFile, $this->rootCategory, null === $this->depth ? 'null' : intval($this->depth), intval($this->includeRoot), intval($this->fetchModels), intval($this->onlyNonEmpty), implode(',', $this->excludedCategories), \Yii::$app->request->url]) . ':' . json_encode($this->additional);
     if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
         return $cache;
     }
     /** @var array|Category[] $tree */
     $tree = Category::getMenuItems(intval($this->rootCategory), $this->depth, boolval($this->fetchModels));
     if (true === $this->includeRoot) {
         if (null !== ($_root = Category::findById(intval($this->rootCategory)))) {
             $tree = [['label' => $_root->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $_root->category_group_id, 'last_category_id' => $_root->id]), 'id' => $_root->id, 'model' => $this->fetchModels ? $_root : null, 'items' => $tree]];
         }
     }
     if (true === $this->onlyNonEmpty) {
         $_sq1 = (new Query())->select('main_category_id')->distinct()->from(Product::tableName());
         $_sq2 = (new Query())->select('category_id')->distinct()->from('{{%product_category}}');
         $_query = (new Query())->select('id')->from(Category::tableName())->andWhere(['not in', 'id', $_sq1])->andWhere(['not in', 'id', $_sq2])->all();
         $this->excludedCategories = array_merge($this->excludedCategories, array_column($_query, 'id'));
     }
     $tree = $this->filterTree($tree);
     $cache = $this->render($this->viewFile, ['tree' => $tree, 'fetchModels' => $this->fetchModels, 'additional' => $this->additional, 'activeClass' => $this->activeClass, 'activateParents' => $this->activateParents]);
     \Yii::$app->cache->set($cacheKey, $cache, 0, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Category::className()), ActiveRecordHelper::getCommonTag(Product::className())]]));
     return $cache;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:31,代码来源:CategoriesList.php

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

示例11: run

 public function run()
 {
     $id = $this->getId();
     $this->plugins = ArrayHelper::merge($this->plugins, ['checkbox']);
     $items = [];
     if (empty($this->selectedItems)) {
         $parent = Category::findById(Yii::$app->request->get('parent_id'));
         while ($parent instanceof Category) {
             $this->selectedItems[] = $parent->id;
             $parent = $parent->parent;
         }
     }
     $this->routes['getTree'] = ArrayHelper::merge($this->routes['getTree'], ['selectedItems' => implode(',', $this->selectedItems)]);
     if (isset($this->routes['edit'])) {
         $items['edit'] = ['label' => Yii::t('app', 'Edit'), 'icon' => 'fa fa-pencil', 'action' => new JsExpression("function (a) {\n                        var \$object = \$(a.reference[0]);\n                        document.location = " . Json::encode(Url::to($this->routes['edit'])) . "\n                            + '?id=' + \$object.attr('data-id') + '&parent_id=' +\n                            \$object.attr('data-parent-id');\n                        }")];
     }
     if (isset($this->routes['open'])) {
         $items['open'] = ['label' => Yii::t('app', 'Open'), 'icon' => 'fa fa-folder-open', 'action' => new JsExpression("function (a) {\n                        var \$object = \$(a.reference[0]);\n                        document.location = " . Json::encode(Url::to($this->routes['open'])) . "\n                            + '?parent_id=' + \$object.attr('data-id');\n                        }")];
     }
     if (isset($this->routes['create'])) {
         $items['create'] = ['label' => Yii::t('app', 'Create'), 'icon' => 'fa fa-plus-circle', 'action' => new JsExpression("function (a) {\n                        var \$object = \$(a.reference[0]);\n                        document.location = " . Json::encode(Url::to($this->routes['create'])) . "\n                            + '?parent_id=' + \$object.attr('data-id');\n                        }")];
     }
     if (isset($this->routes['delete'])) {
         $items['delete'] = ['label' => Yii::t('app', 'Delete'), 'icon' => 'fa fa-trash-o', 'action' => new JsExpression("function (a) {\n                        var \$object = \$(a.reference[0]);\n                        document.location = " . Json::encode(Url::to($this->routes['delete'])) . "\n                            + '?id=' + \$object.attr('data-id');\n                        }")];
     }
     $options = ['state' => ['key' => $this->stateKey], 'plugins' => $this->plugins, 'core' => ['check_callback' => true, 'data' => ['url' => new JsExpression("function (node) {\n                            return " . Json::encode(Url::to($this->routes['getTree'])) . ";\n                        }"), 'data' => new JsExpression("function (node) {\n                            return { 'id' : node.id };\n                        }")], 'multiple' => $this->multiple], 'checkbox' => ['three_state' => false], 'contextmenu' => ['items' => $items], 'dnd' => ['is_draggable' => false]];
     if (count($this->types) > 0) {
         $options['types'] = $this->types;
     }
     $this->selectOptions['id'] = $id . '-select';
     return $this->render('JSSelectableTree', ['id' => $id, 'flagFieldName' => $this->flagFieldName, 'fieldName' => $this->fieldName, 'model' => $this->model, 'multiple' => $this->multiple, 'options' => Json::encode($options), 'routes' => $this->routes, 'selectedItems' => $this->selectedItems, 'selectLabel' => $this->selectLabel, 'selectLabelOptions' => $this->selectLabelOptions, 'selectOptions' => $this->selectOptions, 'selectParents' => $this->selectParents]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:32,代码来源:JSSelectableTree.php

示例12: categoriesSitemap

 protected function categoriesSitemap($parentId = 0, $prefix = '')
 {
     $categories = Category::find()->select(['id', 'category_group_id', 'slug'])->where(['parent_id' => $parentId, 'active' => 1])->asArray(true)->all();
     array_reduce($categories, function ($carry, $item) use($prefix) {
         $this->sitemap->addUrl($prefix . '/' . $item['slug']);
         $this->categoriesSitemap($item['id'], $prefix . '/' . $item['slug']);
         $this->productsSitemap($item['id'], $prefix . '/' . $item['slug']);
     });
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:9,代码来源:SitemapController.php

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

示例14: getForCategoryId

 /**
  * @param $categoryId
  * @return FilterSets[]
  */
 public static function getForCategoryId($categoryId)
 {
     Yii::beginProfile('FilterSets.GetForCategory ' . $categoryId);
     $category = Category::findById($categoryId);
     if ($category === null) {
         return [];
     }
     $categoryIds = $category->getParentIds();
     $filter_sets = FilterSets::find()->where(['in', 'category_id', $categoryIds])->andWhere(['delegate_to_children' => 1])->orWhere(['category_id' => $category->id])->orderBy(['sort_order' => SORT_ASC])->all();
     Yii::endProfile('FilterSets.GetForCategory ' . $categoryId);
     return $filter_sets;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:16,代码来源:FilterSets.php

示例15: getProductType

 protected static function getProductType(Product $model)
 {
     if (!isset(self::$breadcrumbsData[$model->main_category_id])) {
         $parentIds = $model->getMainCategory()->getParentIds();
         $breadcrumbs = [];
         foreach ($parentIds as $id) {
             $breadcrumbs[] = Category::find()->select(['name'])->where(['id' => $id])->asArray()->scalar();
         }
         $breadcrumbs[] = $model->getMainCategory()->name;
         self::$breadcrumbsData[$model->main_category_id] = $breadcrumbs;
     }
     return htmlspecialchars(implode(' > ', self::$breadcrumbsData[$model->main_category_id]));
 }
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:13,代码来源:DefaultHandler.php


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