thinkphp Custom Labels

Source: Internet
Author: User

1. Define TAGLIB directories and files TagLibsmartop. class.php

2. Configuration files

<? PHP     return Array (        ' app_autoload_path ' = ' @ '. TagLib ',  //TagLib Location  @. Indicates the current folder under        ' taglib_build_in ' + ' cx,smartop '       // CX is the name of the Thinkphp base Class library that must be referenced otherwise volist such as tags cannot be used, Smartop is its own defined label name     );? >

3. Defining labels

1     classTaglibsmartopextendstaglib{2         protected $tags=Array(3             //nav definition field attr defines whether close is closed4' Nav ' =Array(' attr ' = ' limit,order ', ' Close ' =>1),5' Child ' =Array(' attr ' = ' limit,order,typeid ', ' Close ' =>1),6' Navnav ' =Array(' attr ' = ' limit,order,typeid ', ' Close ' =>1),7         );8         /**9 * Define LabelsTen * @param the properties accepted $attr array One * @param string accepted by $content string A * @return $str return string -         */ -          Public function_nav ($attr,$content){ the             $tag=$this->parsexmlattr ($attr,$content); -             $Cate= D (' Cate '); -             $result=$Cate->sortchildcate ($Cate->order ($tag[' Order ']) ->limit ($tag[' Limit ']) -Select ()); -             $str= ' '; +             foreach($result  as $k=$v){ -                 //Use the Str_replace () function to replace a string +                 $str.=Str_replace(Array(' [Field:id] ', ' [Field:typename] '),Array($result[$k[' ID '],$result[$k[' name ']),$content); A             } at             return $str; -         } -         /** - * Define label function to be developed is limited to 2 level column call - * @param the properties accepted $attr array - * @param string accepted by $content string in * @return $str return string -         */ to          Public function_child ($attr,$content){ +             $tag=$this->parsexmlattr ($attr,$content); -             $Cate= D (' Cate '); the             $where=Array(' pid ' = =Empty($tag[' typeid '])? 0:$tag[' typeID ']); *             $result=$Cate->where ($where)->order ($tag[' Order ']) ->limit ($tag[' Limit ']) -Select (); $             $str= ' ';Panax Notoginseng             foreach($result  as $k=$v){ -                 //Use the Str_replace () function to replace a string the                 $str.=Str_replace(Array(' [Field:id] ', ' [Field:name] '),Array($v[' ID '],$v[' name ']),$content); +             } A             return $str; the         } +          Public function_navnav ($attr,$content){ -             $tag=$this->parsexmlattr ($attr,$content); $             //use PHP code to return to the template in the form of a string enclosed in single quotation marks  . $             $str= ' <?php '; -             $str. = ' $Cate = M ("Cate"); '; -             $str. = ' $_result = catemodel::sortchildcate ($Cate->select ()); '; the             $str. = ' foreach ($_result as $__catenav): '; -             $str. = ' Extract ($__catenav);? > '; // $.__catenav[ of the array] is removed Wuyi             $str.=$content; AAA the             $str. = ' <?php endforeach?> '; -             return $str; Wu         } -}

4. Templates using tags

1         <NavnavLimit= ' a 'Order= ' IDASC '>2                 <Liclass= ' Nav-lv1-li '>3                     <ahref=""class= ' Top-cate '>{$name}</a>4                     <ul>5                         <foreachItem= ' value 'name= "Child">6                             <Li><ahref="">{$value. Name}</a></Li>7                         </foreach>8                     </ul>9                 </Li>Ten             </Navnav>
1             <navLimit= ' a 'Order= ' IDASC '>2                 <Liclass= ' Nav-lv1-li '>3                     <ahref=""class= ' Top-cate '>[Field:typename]</a>4                     <ul>5                         < ChildLimit= ' a 'Order= ' IDASC ' typeid= "[Field:id]">6                             <Li><ahref="">[Field:name]</a></Li>7                         </ Child>8                     </ul>9                 </Li>Ten             </nav>

thinkphp Custom Labels

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.