ThinkPHP html: list tag usage analysis, thinkphplist_PHP tutorial

Source: Internet
Author: User
ThinkPHP html: list tag usage analysis, thinkphplist. Analysis on the use of html: list tags in ThinkPHP, thinkphplist This article analyzes the use of html: list tags in ThinkPHP. For your reference, refer to the following code: Copy the html in ThinkPHP: list tag usage analysis, thinkphplist

This article analyzes the use of html: list tags in ThinkPHP. We will share this with you for your reference. The details are as follows:

The code is as follows:

The list tag function in ThinkPHP's html tag library is powerful, but there is no documentation. I have to look at the source code. The following is a rough look:

Datasource and show are required. datasource is the data source name, that is, the variable pointed to by assign. show is the most complex and will be discussed later.

Pk is the primary key name and the default value is id. style is a css class.Because the entire list label is compiled into a table, for example, mylist, the table. mylist style in the style sheet will be used here;Check box show check box; action show Operation column

Show: separate different fields with commas, for example:

Id: id | 8%, account: User name | 90px: edit: account, phone: Address, remark: Remarks, status | getStatus: status

Each field is separated by a colon (:) and can be divided into several parts. each part can be separated by a colon (|,

Part 1: id, which indicates the id field in the result set, status | getStatus, which indicates the status field, but must be processed by the getStatus function. the Function here can be a php built-in function, it can also be the common/functions of thinkphp. functions in php can also be conf/common in the project directory. custom functions in php
Part 2: Number | 8% indicates that the field displayed in the title line is the title, the width is 8%, and the user name | 90px in 90px is also the width
Part 3: for example, edit indicates the edit function of javascript. its parameter is the primary key value. for example, if id is 1, the display value at the user name (account) is a link, after clicking it, javascript: edit (1) is executed );
Part 4: You do not need to set this part. for example, an account indicates "username" in the account (username) header line. after you move the cursor over it, "sort by account" is displayed ", if this parameter is not set, it is "sort by user name". that is to say, if this parameter is not set, the words "by" and "sort" are displayed in the same title.

Besides, if action = "true" is set but actionlist is not set, the default "edit" and "delete" operations are displayed. the parameters are the primary key values. in our own function, for example, set changePassword: change the password. The code is as follows: change the password

If there is |, it is somewhat special. The current html tag library forcibly interprets this situation as a status operation, that is, the datasource must have a status field, this field flase, display | the front part; otherwise, it is the back part. for details, refer to: forbid | resume: Disabled | restore. if status is 0, it is disabled. Otherwise, it is restored.

In general, the html: list function is very good, especially the width of each column can be customized. However, there are still some shortcomings or notes that developers need to pay attention:

1. if any | exists in the actionlist, it will be checked with the status field in datasource. this is very unpleasant. because there may be more than two states, and other fields may also need to display different texts as needed to perform different operations.
2. the link is expressed in javascript. sometimes it is okay, but sometimes it is expected to be expressed directly in url, such as editing
3. the javascript function name in the link is very easy to name with some html elements. it may conflict with some js scripts or html element names, such as del, change, edit, over, out, etc, for html elements such as checkbox, the id is check.
4. the sorting by XX function of titles cannot be disabled. This function is not required in many cases, especially for each line. of course, it can be modified in js functions.
5. none of the above js functions are defined in tags, but they are called. the function is defined in my own js script. I am using the thinkphp RABC example directly, so I have not studied the specific js file, and I do not want to study it for the moment. however, if you have added custom operations, you have to write your own js functions.

The tag library of TP is a good thing.

For example, you can write a list of tags that contain check boxes as follows:
The code is as follows:

I will not talk about the id and name.
Datasource is the content transmitted by PHP code.
Show: "" contains the column information of the table.
Id: ID indicates the id of the field in datasource, which is displayed in the column with ID.

If yes
Article title: function

It means that the content under the field "articleTitle" is displayed in the "article title" column, and a javascript: function ("primary key") is added for each "Article Title ") for other operations

Checkbox = "true" indicates that the check box is displayed.
Style = "list" indicates the list style.
Action = "true" indicates that the operation column is displayed.
Actionlist = "edit: edit, delarticle: delete, sh: Audit" indicates the content of the operation column.

Format:

Execution function: Display name.

I hope this article will help you design PHP programs based on the thinkPHP framework.

Articles you may be interested in:
  • In thinkphp, the html: list tag transmits multiple parameter instances.
  • How to use thinkPHP Html template labels
  • ThinkPHP adopts Implement three-level cyclic code instances
  • Thinkphp volist label nested loop tutorial
  • Method for verifying the last record of the volist loop in the ThinkPHP Template
  • Usage of volist labels in Thinkphp
  • Thinkphp Special Label Usage overview
  • Custom tag library instances in the ThinkPHP Group
  • ThinkPHP tag creation tutorial

Examples in this article analyze the use of html: list tags in ThinkPHP. The code is as follows...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.