Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The steps of making ThinkPHP tags

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the "ThinkPHP tag production steps", in daily operation, I believe many people have doubts about the ThinkPHP tag production steps, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, I hope to answer the "ThinkPHP tag production steps" doubts helpful! Next, please follow the small series to learn together!

Here we add a label resolution to this class.

I. Label format:

Second, the role of labels:

Loop outputs columns whose parent id is parentid

III. Operation steps:

1. Add to the private properties of tagLibCx.class:

'category'=array('attr'=>'parentid',level=>3)

where attr: attribute level of tag Nested hierarchy of tag

2. Add an analytic function

The parsing principle of tags is to get the corresponding information by reading xml files, and then piece together the php source code needed, and finally output it on the page through echo.

The specific codes are as follows:

public function _category($attr,$content){//Parse all attributes of tag into $tag array $tag = $this->parseXmlAttr($attr,'category');//Get attributes in tag $parentid= $tag <$'parentid'];//Define variables for page parsing $result = ! empty($tag['result'])?$ tag <$'result ']:'cat'; //Defines the result storage variable $key = ! empty($tag['key'])?$ tag['key']:'i';$mod = isset($tag['mod'])?$ tag['mod']:'2';//Patch database query statements Here is a function wrapped directly in CategoryModel $sql = "D ('Category')->";$sql .= "getCategorys(".$ parentid. ')';//patchwork output characters $parsestr ='';$parsestr .= $content;//parse content in category tag $parsestr .= '';return $parsestr;}

getCategorys method in CategoryModel:

/** Get column information according to parentid * $parentid parent id* $withSelf whether contains itself */public function getCategorys ($parentid,$withSelf=0){$parentid=intval ($parentid);$categorys=$this->where (array('parentid'=>$parentid,'ismenu'=>1))->order ('listorder ASC')->select();//contains self if($withSelf){$categorys2=$this->where(array('id'=>$parentid,'ismenu'=>1))->limit(1)->select();$category=array_merge($categorys,$categorys2);}return $categorys;}

3. References on the page:

A label like that is done! We can get rid of that volist and dynamically output what we want on the page!

At this point, the study of "ThinkPHP tag production steps" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report