本文整理汇总了PHP中CGlobal::categoriesTree方法的典型用法代码示例。如果您正苦于以下问题:PHP CGlobal::categoriesTree方法的具体用法?PHP CGlobal::categoriesTree怎么用?PHP CGlobal::categoriesTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGlobal
的用法示例。
在下文中一共展示了CGlobal::categoriesTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCategoriesTree
static function getCategoriesTree($get_direct = false, $hide = false)
{
if (!CGlobal::$categoriesTree) {
self::getCats();
$categories = array();
if ($get_direct) {
$topcat = array();
$subcatlv2 = array();
$sql = 'SELECT * FROM category';
if ($hide) {
$sql .= ' WHERE status != "HIDE" AND category.ref_id = 0';
}
$sql .= ' ORDER BY parent_id, position';
$re = DB::query($sql);
if ($re) {
while ($cat = mysql_fetch_assoc($re)) {
if ($cat['status'] == 'HIDE') {
$cat['name'] .= ' (đã ẩn)';
}
if ($cat['parent_id']) {
$subcatlv2[$cat['parent_id']][$cat['id']] = $cat;
} else {
$topcat[$cat['id']] = $cat;
}
}
}
$subcat = array();
foreach ($topcat as $cat) {
if (isset($subcatlv2[$cat['id']])) {
foreach ($subcatlv2[$cat['id']] as $sc) {
$subcat[$sc['id']] = $sc;
//if current sub category level 2
}
$cat['childs'] = $subcat;
$categories[$cat['id']] = $cat;
$subcat = array();
}
}
} else {
if (CGlobal::$subCategories) {
$subcat = CGlobal::$subCategories;
foreach ($subcat as $id => $sub_cat) {
if (isset(CGlobal::$allCategories[$id])) {
$cat = CGlobal::$allCategories[$id];
if ($cat['ref_id'] == 0) {
$childs = array();
foreach ($sub_cat as $sid => $cat2) {
if ($cat2['ref_id'] == 0) {
$childs[$sid] = $cat2;
}
}
$cat['childs'] = $childs;
$categories[$id] = $cat;
}
}
}
}
}
CGlobal::$categoriesTree = $categories;
}
//echo "<pre>";
//print_r(CGlobal::$categoriesTree);
return CGlobal::$categoriesTree;
}