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