thinkphp template Custom Label Usage _php Tutorial

Source: Internet
Author: User
Tags list of attributes
The use of template tags can make the site foreground development faster and simpler, the use of Dedecms, PHPCMS and other content management systems should be aware that the CMS front desk is to use template tags to invoke data. To invoke the list of articles as an example:

Dedecms can be written as:

 
  
  
    {dede:arclist row= ' orderby= ' id desc ' titlelen= '}
  • [Field:title]
  • {/dede:arclist}

Phpcms can be written as:

 
  
  
    {pc:content action= "hits" catid= "6" num= "ten" order= "Views DESC"} {Loop $data $r}
  • {$r [title]}
  • {/loop} {/PC}

Thinkphp's custom tags also enable such a powerful feature. Thinkphp custom tags are implemented through the tag extension library. and thinkphp itself with a tag extension library as long as we inherit taglib will be able to meet the definition of their own label.

Naming conventions:

taglib+ Tag Library name. class.php

The following is an example of implementing call navigation as an illustration

The file TagLibNav.class.php is as follows:

<?phpclass Taglibnav extends TagLib {  //attr attribute list   //close closed (0 or 1 default 1)  //alias tag alias  //level nesting level The c4/>//tag is defined as follows:  protected $tags = Array (' nav ' = = Array (' attr ' = '    limit,order ', ' level ' = + 3, ' close ' => ; 1),  );  Define Query Database label  //attr is a list of attributes, $content is the public  function _nav ($attr, $content) that stores the contents between tags {    $tag = $this Parsexmlattr ($attr, $content);    $cate =m (' Channel ');    $TB = $cate->order ($tag [' Order '])->limit ($tag [' limit '])->select ();    $str = ";    for ($i =0; $i
 
  

How HTML pages are called:

 
       Tablist     
 
  
  
  • Home
  • [Filed:name]

Configuration file:

' App_autoload_path ' = ' @ '. TagLib ',  //taglib's position  @. Indicates the current folder under ' taglib_build_in ' = ' cx,nav ',       // CX is the name of the Thinkphp base Class library that must be referenced otherwise volist such as labels cannot be used, NAV is its own defined label name

Controller:

<?phpclass Indexaction extends action{public  function Index () {    $this->display ();}  }? >

The custom label has been implemented so that there is no need to write much code in the controller.

http://www.bkjia.com/PHPjc/824769.html www.bkjia.com true http://www.bkjia.com/PHPjc/824769.html techarticle The use of template tags can make the site foreground development faster and simpler, the use of Dedecms, PHPCMS and other content management system should be aware that the CMS front desk is to use template tags to call ...

  • 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.