thinkphp Enable breadcrumb navigation (current location) example Sharing _php Tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.