Home  >  Article  >  Backend Development  >  Analysis on the usage of html:list tag in ThinkPHP, thinkphplist_PHP tutorial

Analysis on the usage of html:list tag in ThinkPHP, thinkphplist_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:01:101267browse

Analysis of the usage of html:list tag in ThinkPHP, thinkphplist

This article analyzes the usage of html:list tag in ThinkPHP with examples. Share it with everyone for your reference, the details are as follows:

Copy code The code is as follows:

The list tag in ThinkPHP's html tag library is powerful, but there is no documentation. I have to look at the source code. After a casual look, it is roughly as follows:

Datasource and show are required. Datasource is the name of the data source, which is the variable pointed to by assign. Show is the most complicated one. , we will talk about it later

pk is the primary key name, the default is id; style is the class of CSS style , because the entire list tag will be compiled into a table, for example, here is mylist, then the table.mylist style in the style sheet is Will be used here; whether checkbox displays the check box; whether action displays the action column

show part: Separate different fields with commas, such as:

id:number|8%,account:username|90px:edit:account,phone:address,remark:note,status|getStatus:status

Each field can be divided into several parts with colon as the separator, and each part can be separated by |,

The first part: id, represented as the id field in the result set, status|getStatus, represents the status field, but it needs to be processed by the getStatus function. The function here can be PHP's own function, or it can be thinkphp's common/functions. Functions in php can also be custom functions in the project directory conf/common.php
Part 2: Number | 8% means that the display field in the title row is the title, the width is 8%, user name | 90px in 90px is also the width
The third part: such as edit, represents the edit function of javascript. Its parameter is the primary key value. For example, for a user with id 1, the displayed value at the username (account) is a link. After clicking, javascript:edit(1) will be executed. ;
Part 4: This part generally does not need to be set. For example, the account number means that when the "user name" in the title line of the account (user name) is moved with the mouse, "Sort by Account" will be displayed. If not set, it will be "Sort by User". "Sort by name", that is to say, if it is not set, the words between "by" and "sort" will display the same as the title.

As for actionlist, if action="true" is set, but actionlist is not set, the default "edit" and "delete" operations will be displayed, and the parameters are all the values ​​of the primary key. In terms of our self-set function , for example, set to changePassword: change password, it will become something like Copy code The code is as follows:disable, otherwise In general, the html:list function is very good, especially the ability to customize the width of each column. However, there are still some shortcomings or some areas that developers need to pay attention to :

1. If there is | in the actionlist, it will be linked to the status field in the datasource. This is very unpleasant. Because there may be more than two statuses, and secondly, other fields may also need to display different text and perform different executions according to the situation. Operation.
2. The link is expressed in javascript, which is okay sometimes, but sometimes I prefer to express it directly in url, such as
edit
3. The javascript function naming in the link and the naming of some html elements are very simple, and may conflict with the naming of some js scripts or html elements. Function names such as del, change, edit, over, out, etc., html elements such as checkbox The id is check
4. The function of sorting the title by XX cannot be disabled. There are many times when this function is not needed, especially when every row is not required to have this function. Of course, it can be modified in the js function.
5. The above js functions are not defined in tags, but only called. The functions are defined in their own js scripts. I directly used the RABC example of thinkphp, so I did not study the specific js files, and I don’t want to study them for the time being. . But if you add custom operations, you have to write your own js function

TP’s tag library is a good thing.

For example, a label list containing checkboxes could be written like this:
Copy code The code is as follows:

Not much to say about id and name
datasource is the content information passed by the PHP code
show:""Inside is the column information of the table
id: ID represents the information in the datasource with the field name id, which is displayed under the column named ID
.

If yes
articleTitle: Article title: function

means that the content under the field articleTitle is displayed under the "article title" column. At the same time, a javascript:function ("primary key") link is added to each "article title" for other operations.

checkbox="true" means displaying the checkbox
style="list" represents the style using list.
action="true" means displaying the action column
actionlist="edit: edit, delarticle: delete, sh: review" represents the content of the action column

Format:

Execute function: display name.

I hope this article will be helpful to everyone’s PHP programming based on the thinkPHP framework.

Articles you may be interested in:

  • The html:list tag in thinkphp passes multiple parameter instances
  • How to use thinkPHP’s Html template tags
  • ThinkPHP Using to implement a three-level loop code example
  • Thinkphp's volist tag nested loop usage tutorial
  • Verification method to determine the last record of the volist loop in the ThinkPHP template
  • Introduction to the usage of volist tags in Thinkphp
  • Overview of the usage of thinkphp special tags
  • Custom tag library examples under ThinkPHP group
  • ThinkPHP tag production tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1089932.htmlTechArticleAnalysis of the usage of html:list tag in ThinkPHP, thinkphplist This article analyzes the usage of html:list tag in ThinkPHP. Share it with everyone for your reference, the details are as follows: Copy the code The code is as follows...
Statement:
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