Kill lui Lei dog thinkphp project----Enterprise Website 28 website The implementation of the left navigation of the foreground

Source: Internet
Author: User

We are modifying the code based on the top-level classification we just found in the model layer:

<?phpnamespace Home\controller; UseThink\controller;classCommoncontrollerextendsController {function__construct () {//inherits the construction method of the parent class, so the Web site executes it first .Parent::__construct (); //start of the display of the head level two classification        $mod= M ("Category"); $where[' cate_pid '] = ' 0 '; //This can result in an anti-SQL injection.        $cate=$mod, where ($where), select ();//get the result set for top column 0        $thisAssign (' Cate ',$cate); //dump ($cate); End of the display of the head level two category                            if($cateid= I (' cate_id ')) {//Add this decision to avoid the main page error, because the first page does not receive any information//list page and product page breadcrumb navigation started            $mod= D (' Category '); $res=$mod-GetParent ($cateid); //dump ($res);            $this-Assign (' Res ',$res); //breadcrumb navigation end of List page and product page//Get current column start            $cateone=$mod, where ("cate_id=$cateid")find (); $thisAssign (' Cateone ',$cateone); //get the end of the current column//get started with top-level columns            if($cateone[' cate_pid ']! = ' 0 '){                //if it's not equal to 0, you need to find his top column from Cate_pid.                $pid=$cateone[' Cate_pid ']; $catetop=$mod, where ("cate_id=$pid")find (); $thisAssign (' Catetop ',$catetop); //here is the left navigation start                $topid=$catetop[' cate_id '];//Remove the ID of the top column                $cateson=$mod, where ("cate_pid=$topid"), select ();//It's the equivalent of finding my son's father                $thisAssign (' Cateson ',$cateson); //dump ($cateson); This is the left navigation end .}Else{                //if it equals 0, it is directly equal to the top column                $catetop=$cateone; $thisAssign (' Catetop ',$catetop); //Top column to find sub-column start                $topid=$catetop[' cate_id '];//Remove the ID of the top column                $cateson=$mod, where ("cate_pid=$topid"), select ();//It's the equivalent of finding my son's father                $thisAssign (' Cateson ',$cateson); //Top column to find the end of the sub-column            }        }            }}

Then assign to the lists.html and page.html templates:

Under test:

has been able to successfully call,,, YES, but found a problem, our home page can not be used,

Then we commonController.class.php home is also inherited this, but home no cate_id, so we give a judge his problem can be solved:

So we can solve the problem ....

Kill lui Lei dog thinkphp project----Enterprise Website 28 website The implementation of the left navigation of the foreground

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.