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)

Source: Internet
Author: User

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)

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.