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