When we achieve the site level two classification display, the first consideration is to take the top-level columns directly, the controller code is as follows:
<?phpnamespace Home\controller; UseThink\controller;classIndexcontrollerextendsController { Public functionindex () {$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); $this-display (); }}
Because our top-level column has a cate_id of 0, we just take out all the columns cate_id=0 and walk through to the template page to leave:
This allows us to show the first-level columns:
The next step is to look for his father through the cate_pid we currently find, so we create a function.php function file in the Web\common\common directory to look for our dad, hehe:
The code looks like this:
<? PHP // Remove sub-columns function getsub ($pid) { $mod = D ("Category"); $where $pid ; $cmod $mod , where ($where), Select (); return $cmod ; }
We receive the incoming ID in the function to find cate_pid = The data of the ID we passed in, and then return it with return ...
The next step is to introduce our functions directly under the model:
<DivID= "header"> <Divclass= "Layout"> <DivID= "NAV"> <Divclass= "NAV"> <ul> <Li><ahref="/"class= "header Foucs"> <P>Website Home</P> <Pclass= "en">Home</P> </a> </Li> <volistname= "Cate"ID= "Vo"> <binclass= "Mnav"> <ahref= "/plus/list.php?tid=1"class= ' '><P>{$vo [' Cate_name ']}</P><Pclass= ' en '>{$vo [' Cate_ename ']}</P></a> <ulclass= "Smenu"> <volistname= ": Getsub ($vo [' cate_id '])"ID= "VV"> <Li> <ahref= "/plus/list.php?tid=11">{$VV [' Cate_name ']}</a> </Li> </volist> </ul> </Li> </volist> </ul> </Div> </Div> <Divclass= "logo"> <ahref="/"></a> </Div> </Div></Div>
This will find the data in our level two classification, if it is a class three or four class, so the analogy can be realized ....
The implementation effect is as follows:
Kill lui Lei dog thinkphp project----Corporate website 21 of the site front desk two category display name (TP Custom Function show infinite Pole classification)