ThinkPHP标签制作教程
这篇文章主要介绍了ThinkPHP标签制作方法,需要的朋友可以参考下
本文以实例讲解了ThinkPHP标签的制作方法,对于ThinkPHP的初学者或者开发人员都有一定的借鉴价值。
一般来说,ThinkPHP的默认标签解析器在Lib/Template/TagLib/TagLibCx.class(2.1版本位于ThinkPHP/Lib/Think/Template/TagLib/TagLibCx.class.php)中,里面定义了常用的如volist php 等常用ThinkPHP的标签
这里我们就在这个类中添加一个
一、标签格式:
二、标签作用:
循环输出父类id是parentid的栏目
三、操作步骤:
1.在tagLibCx.class 的私有属性中添加:
'category'=array('attr'=>'parentid',level=>3)
其中attr:标签的属性 level标签的嵌套层次
2.添加解析函数
标签的解析原理就是通过读取xml文件得到相应的信息,,然后再拼凑成所需要的php源代码,最后通过echo 在页面上输出。
具体代码如下:
public function _category($attr,$content) { //把标签的所有属性解析到$tag数组里面 $tag = $this->parseXmlAttr($attr,'category'); //得到标签里面的属性 $parentid= $tag['parentid']; //定义页面解析的变量 $result = !empty($tag['result'])?$tag['result']:'cat'; //定义数据查询的结果存放变量 $key = !empty($tag['key'])?$tag['key']:'i'; $mod = isset($tag['mod'])?$tag['mod']:'2'; //拼凑数据库查询语句 这里直接用了CategoryModel封装好的函数 $sql = "D('Category')->"; $sql .= "getCategorys(".$parentid.')'; //拼凑输出字符 $parsestr = '$'.$result.'):'; $parsestr .= '++$'.$key.';$mod = ($'.$key.' % '.$mod.' );?>'; $parsestr .= $content;//解析在category标签中的内容 $parsestr .= ''; return $parsestr; }
CategoryModel中的getCategorys方法:
/* * 根据parentid得到栏目信息 * $parentid 父id * $withSelf 是否包含自己 */ public function getCategorys($parentid,$withSelf=0) { $parentid=intval($parentid); $categorys=$this->where(array('parentid'=>$parentid,'ismenu'=>1))->order('listorder ASC')->select(); //包含自己 if($withSelf) { $categorys2=$this->where(array('id'=>$parentid,'ismenu'=>1))->limit(1)->select(); $category=array_merge($categorys,$categorys2); } return $categorys; }
3.页面上的引用:
这样一个标签就做好了!!就可以甩掉那个volist在页面上动态输出我们想要的东西了!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

1. Start PPT, create a new blank document, select all text boxes and delete them. 2. Execute the Insert-Shape command, drag a rectangle in the document, and fill the shape with black. 3. Drag the rectangle to elongate it, execute the Insert-Shape command, drag out the small square, and set the fill color to white. 4. Copy and paste the small squares one by one so that the top and bottom are evenly distributed on both sides of the film. After selecting them all with ctrl+a, right-click and select Group. 5. Execute the Insert-Picture command, find the picture to be inserted in the pop-up dialog box, click to open, and adjust the size and position of the picture. 6. Repeat step 5 to insert and set the remaining pictures in order to form a film picture. 7. Select the film, execute animation-add animation command

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to make the cover of Tomato novel? You can make exclusive novel cover in Tomato novel, but most friends don’t know how to make the cover of Tomato novel. Next is the picture of how to make the cover of Tomato novel brought by the editor to the players. Tutorial, interested players come and take a look! Tomato Novel usage tutorial How to make a Tomato Novel cover 1. First open the Tomato Novel APP, enter the work management page to create a new book, and select the [Cover Template] as shown by the arrow below; 2. Then enter the cover template page and select your favorite cover Template; 3. After finally selecting the cover, click [Confirm] in the upper right corner.
