Table of Contents
ThinkPHP的标签制作,ThinkPHP标签制作
Home php教程 php手册 ThinkPHP的标签制作,ThinkPHP标签制作

ThinkPHP的标签制作,ThinkPHP标签制作

Jun 13, 2016 am 08:46 AM
lib thinkphp make device exist Label of parse default

ThinkPHP的标签制作,ThinkPHP标签制作

thinkphp的默认标签解析器在Lib/Template/TagLib/TagLibCx.class中 里面定义了常用的volist php 等常用thinkphp的标签 这里笔者在这个类中添加一个的标签解析   标签格式: 标签作用: 循环输出父类id是parentid的栏目   1.在tagLibCx.class 的私有属性中添加 'category'=array('attr'=>'parentid',level=>3) 其中attr:标签的属性 level标签的嵌套层次   2.添加解析函数 标签的解析原理就是通过读取xml文件得到相应的信息,然后再拼凑成所需要的 php源代码,最后通过echo 在页面上输出 具体代码如下:
 <br />public function _category($attr,$content)<br />{<br />//把标签的所有属性解析到$tag数组里面<br />$tag = $this->parseXmlAttr($attr,'category');<br /> <br />//得到标签里面的属性<br />$parentid= $tag['parentid'];<br /> <br />//定义页面解析的变量<br />$result = !empty($tag['result'])?$tag['result']:'cat'; //定义数据查询的结果存放变量<br />$key = !empty($tag['key'])?$tag['key']:'i';<br />$mod = isset($tag['mod'])?$tag['mod']:'2';<br /> <br />//拼凑数据库查询语句 这里直接用了CategoryModel封装好的函数<br />$sql = "D('Category')->";<br />$sql .= "getCategorys(".$parentid.')';<br /> <br />//拼凑输出字符<br />$parsestr = '<?php $_result='.$sql.'; if ($_result): $'.$key.'=0;';<br />$parsestr .= 'foreach($_result as $key=>$'.$result.'):';<br />$parsestr .= '++$'.$key.';$mod = ($'.$key.' % '.$mod.' );?>';<br />$parsestr .= $content;//解析在category标签中的内容<br />$parsestr .= '<?php endforeach; endif;?>';<br />return $parsestr;<br /> <br />}<br /> <br />CategoryModel中的getCategorys方法<br />/*<br />* 根据parentid得到栏目信息<br />* $parentid 父id<br />* $withSelf 是否包含自己<br />*/<br /> <br />public function getCategorys($parentid,$withSelf=0)<br />{<br />$parentid=intval($parentid);<br />$categorys=$this->where(array('parentid'=>$parentid,'ismenu'=>1))->order('listorder ASC')->select();<br />//包含自己<br />if($withSelf)<br />{<br />$categorys2=$this->where(array('id'=>$parentid,'ismenu'=>1))->limit(1)->select();<br />$category=array_merge($categorys,$categorys2);<br />}<br />return $categorys;<br /> <br />}
Copy after login
  3.页面上的引用   这样一个标签就做好了 ^_^!就可以甩掉那个volist在页面上动态输出我们想要的东西了
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

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.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

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.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

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.

Specific method to create film movement effect in PPT Specific method to create film movement effect in PPT Mar 26, 2024 pm 04:00 PM

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

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

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 install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

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.

Analysis of new features of Win11: How to skip logging in to Microsoft account Analysis of new features of Win11: How to skip logging in to Microsoft account Mar 27, 2024 pm 05:24 PM

Analysis of new features of Win11: How to skip logging in to a Microsoft account. With the release of Windows 11, many users have found that it brings more convenience and new features. However, some users may not like having their system tied to a Microsoft account and wish to skip this step. This article will introduce some methods to help users skip logging in to a Microsoft account in Windows 11 and achieve a more private and autonomous experience. First, let’s understand why some users are reluctant to log in to their Microsoft account. On the one hand, some users worry that they

Analysis of the meaning and usage of midpoint in PHP Analysis of the meaning and usage of midpoint in PHP Mar 27, 2024 pm 08:57 PM

[Analysis of the meaning and usage of midpoint in PHP] In PHP, midpoint (.) is a commonly used operator used to connect two strings or properties or methods of objects. In this article, we’ll take a deep dive into the meaning and usage of midpoints in PHP, illustrating them with concrete code examples. 1. Connect string midpoint operator. The most common usage in PHP is to connect two strings. By placing . between two strings, you can splice them together to form a new string. $string1=&qu

See all articles