Before the column is very few, the dead way to do (the name of the column), now more columns, gradually two columns, three columns also came, this way is obviously not suitable, so it improved a bit. It is not difficult to use a recursive function to do it.
Examples of Use:
Copy CodeThe code is as follows:
Current position-The first parameter CATID is the ID of the current column, the second parameter is the title of the article, the second parameter is empty when calling the current position of the column.
$this->assign ("Now_here", $this->now_here ($catid, $res [' title ']);
Implementation code:
Copy the Code code as follows:
Explain, the column table category in the CATID column id,catname for the column name, Asmenu as the column parent ID, when the top column, Asmenu for 0.
protected function Now_here ($catid, $ext = ") {
$cat = M ("Category");
$here = ' home ';
$uplevels = $cat->field ("Catid,catname,asmenu")->where ("catid= $catid")->find ();
if ($uplevels [' asmenu ']! = 0)
$here. = $this->get_up_levels ($uplevels [' Asmenu ']);
$here. = '. $uplevels [' CatName ']. "";
if ($ext! = ") $here. = '. $ext;
return $here;
}
protected function Get_up_levels ($id) {
$cat = M ("Category");
$here = ";
$uplevels = $cat->field ("Catid,catname,asmenu")->where ("catid= $id")->find ();
$here. = '. $uplevels [' CatName ']. "";
if ($uplevels [' asmenu ']! = 0) {
$here = $this->get_up_levels ($uplevels [' Asmenu ']). $here;
}
return $here;
}
Attached: Another example
Copy the Code code as follows:
Class Indexaction extends Action {
Public Function Cat () {
Load (' extend '); Load the extend.php file
Remove all the Categories
$Categories = M (' Categories ')->select ();
$nav _array = Array ();
$this->getnavcrumbs ($Categories, 2120, $nav _array);
Dump ($nav _array);
Remove all categories (and construct them into a tree)
$CategoryTree = List_to_tree ($Categories, ' categories_id ', ' parent_id ');
}
/**
* Build breadcrumbs up to the classification ID
* @param $Categories An array of all classifications
* @param $categoryId the category ID to be used for upward backtracking
* @param $navCrumbs An array for saving results, passing in an empty array.
*/
Public Function Getnavcrumbs ($Categories, $categoryId, & $navCrumbs) {
$category = List_search ($Categories, Array (' categories_id ' = $categoryId));
$category = $category [0];
$parent _id = $category [' parent_id '];
$categories _id = $category [' categories_id '];
if ($parent _id! = 0) {//0 here is the root node ID (root node ID)
$this->getnavcrumbs ($Categories, $parent _id, $navCrumbs);
}
$navCrumbs [$categories _id] = $category;
}
}
http://www.bkjia.com/PHPjc/768136.html www.bkjia.com true http://www.bkjia.com/PHPjc/768136.html techarticle before the column very few, the dead way to do (home-column name), now more columns, gradually two-level columns, three columns also came, this way is obviously not appropriate, so ...