Home Backend Development PHP Tutorial ThinkPHP label production_PHP tutorial

ThinkPHP label production_PHP tutorial

Jul 13, 2016 pm 05:47 PM
lib template thinkphp make device exist Label of parse default

thinkphp’s default tag parser is in Lib/Template/TagLib/TagLibCx.class

It defines commonly used volist php and other commonly used thinkphp tags

Here the author adds a tag parsing

to this class

Tag format:

<{$cat.catname}>

Tag function:

Loop out the column whose parent ID is parentid

1. Add

in the private attribute of tagLibCx.class

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

Among them, attr: the attribute level of the tag and the nesting level of the tag

2. Add parsing function

The principle of tag parsing is to obtain the corresponding information by reading the xml file, and then piece it together into the required

php source code, finally output on the page through echo

The specific code is as follows:

public function _category($attr,$content)

{

//Parse all attributes of the tag into the $tag array

$tag = $this->parseXmlAttr($attr,'category');

//Get the attributes in the tag

$parentid= $tag['parentid'];

//Define variables for page parsing

$result = !empty($tag['result'])?$tag['result']:'cat'; //Define data query result storage variables

$key = !empty($tag['key'])?$tag['key']:'i';

$mod = isset($tag['mod'])?$tag['mod']:'2';

//Piece together the database query statement. Here we directly use the function encapsulated by CategoryModel

$sql = "D('Category')->";

$sql .= "getCategorys(".$parentid.')';

//Piece together the output characters

$parsestr = '

$parsestr .= 'foreach($_result as $key=>$'.$result.'):';

$parsestr .= '++$'.$key.';$mod = ($'.$key.' % '.$mod.' );?>';

$parsestr .= $content;//Parse the content in the category tag

$parsestr .= '';

return $parsestr;

}

getCategorys method in CategoryModel

/*

* Get column information based on parentid

* $parentid parent id

* Whether $withSelf contains self

*/

public function getCategorys($parentid,$withSelf=0)

{

$parentid=intval($parentid);

$categorys=$this->where(array('parentid'=>$parentid,'ismenu'=>1))->order('listorder ASC')->select();

//include self

if($withSelf)

{

$categorys2=$this->where(array('id'=>$parentid,'ismenu'=>1))->limit(1)->select();

$category=array_merge($categorys,$categorys2);

}

return $categorys;

}

3. Quotes on the page

<{$cat.catname}>

Such a tag is ready^_^! We can get rid of the volist and dynamically output what we want on the page

Excerpted from Wok

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478508.htmlTechArticlethinkphp’s default tag parser defines the commonly used volist php in Lib/Template/TagLib/TagLibCx.class For commonly used thinkphp tags, the author adds a catego to this class...
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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.

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

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.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

See all articles