本文整理汇总了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;
}
示例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;
}