ThinkPHP label production_PHP tutorial
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 format:
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

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

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

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.

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

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] 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

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.

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.
