In thinkphp, the html: list tag transmits multiple parameter instances.

Source: Internet
Author: User
This article describes how to pass multiple parameters through the html: list tag in thinkphp. it is of great practical value in processing parameter transfer. For more information, see ThinkPHP.

This article describes how to solve the problem of passing multiple parameters through the html: list tag in thinkphp. The specific analysis is as follows:

This change is effective for thinkphp 2.0 and not tested for thinkphp 3.0.
This file is mainly used to modify the _ list method of/Thinkphp/Lib/Think/Template/Taglib/TabLibHtml. class. php.

The code section for commenting on new content is newly added.
Multiple parameters are separated by commas ,)

The code is as follows:

Public function _ list ($ attr)
{
$ Tag = $ this-> parseXmlAttr ($ attr, 'list ');
$ Id = $ tag ['id']; // table id
$ Datasource = $ tag ['datasource ']; // name of the data source VoList displayed in the list
$ Pk = empty ($ tag ['PK'])? 'Id': $ tag ['PK']; // primary key name. The default value is id.
$ Style = $ tag ['style']; // style name
$ Name =! Empty ($ tag ['name'])? $ Tag ['name']: 'vo'; // vo object name
$ Action = $ tag ['action'] = 'true '? True: false; // whether to display the function
$ Key =! Empty ($ tag ['key'])? True: false;
$ Sort = $ tag ['sort '] = 'false '? False: true;
$ Checkbox = $ tag ['checkbox']; // whether to display checkbox
If (isset ($ tag ['actionlist']) {
$ Actionlist = explode (',', trim ($ tag ['actionlist']); // specify the function list
}
If (substr ($ tag ['show '], 0, 1) =' $ '){
$ Show = $ this-> tpl-> get (substr ($ tag ['show '], 1 ));
} Else {
$ Show = $ tag ['show'];
}
$ Show = explode (',', $ show); // The field list is displayed in the list.
// Calculate the number of columns in the table
$ ColNum = count ($ show );
If (! Empty ($ checkbox) $ colNum ++;
If (! Empty ($ action) $ colNum ++;
If (! Empty ($ key) $ colNum ++;
// Display start
$ ParseStr =" N ";
$ ParseStr. ='

















































';$ ParseStr. =' ';$ ParseStr. =' ';// Fields to be displayed in the list$ Fields = array ();Foreach ($ show as $ val ){$ Fields [] = explode (':', $ val );}If (! Empty ($ checkbox) & 'true' = strtolower ($ checkbox) {// if you specify to display the checkbox column$ ParseStr. =' ';}If (! Empty ($ key )){$ ParseStr. =' ';}Foreach ($ fields as $ field) {// display the specified field$ Property = explode ('|', $ field [0]);$ Showname = explode ('|', $ field [1]);If (isset ($ showname [1]) {$ ParseStr. =' ';} Else {$ ParseStr. = $ showname [0].'';}}If (! Empty ($ action) {// if you specify to display the operation function column$ ParseStr. =' ';}$ ParseStr. =' ';$ ParseStr. =' If (! Empty ($ checkbox )){$ ParseStr. = 'onmouseover = "over (event)" onmouseout = "out (event)" onclick = "change (event )"';}$ ParseStr. = '> ';If (! Empty ($ checkbox) {// If you need to display the checkbox, the checkbox is displayed at the beginning of each line.$ ParseStr. =' ';}If (! Empty ($ key )){$ ParseStr. =' ';}Foreach ($ fields as $ field ){// Display the defined list fields$ ParseStr. =' ';}If (! Empty ($ action) {// Display operationIf (! Empty ($ actionlist [0]) {// display the specified function item$ ParseStr. =' ';// Echo $ parseStr;// Exit ();}}$ ParseStr. ='
No';
} Else {
$ ParseStr. ='
';
}
$ Showname [2] = isset ($ showname [2])? $ Showname [2]: $ showname [0];
If ($ sort ){
$ ParseStr. = ''. $ showname [0].'
Operation
{$ I}';
If (! Empty ($ field [2]) {
// The List Field link function is implemented by the JS function.
$ Href = explode ('|', $ field [2]);
If (count ($ href)> 1 ){
// Specify the field value passed by the link
// Supports passing multiple fields
$ Array = explode ('^', $ href [1]);
If (count ($ array)> 1 ){
Foreach ($ array as $ ){
$ Temp [] = ''{$ '. $ name.'. '. $ a.' | addslashes }'';
}
$ ParseStr. = '';
} Else {
$ ParseStr. = '';
}
} Else {
// If no default serial number is specified
$ ParseStr. = '';
}
}
If (strpos ($ field [0], '^ ')){
$ Property = explode ('^', $ field [0]);
Foreach ($ property as $ p ){
$ Unit = explode ('|', $ p );
If (count ($ unit)> 1 ){
$ ParseStr. = '{$'. $ name. '.'. $ unit [0]. '|'. $ unit [1]. '}';
} Else {
$ ParseStr. = '{$'. $ name. '.'. $ p .'}';
}
}
} Else {
$ Property = explode ('|', $ field [0]);
If (count ($ property)> 1 ){
// Convert -- Yes. multiple parameters are passed.
$ Property [1] = str_replace ('--', $ property [1]); // add content here
$ ParseStr. = '{$'. $ name. '.'. $ property [0]. '|'. $ property [1]. '}';
} Else {
$ ParseStr. = '{$'. $ name. '.'. $ field [0]. '}';
}
}
If (! Empty ($ field [2]) {
$ ParseStr. = '';
}
$ ParseStr. ='
';
Foreach ($ actionlist as $ val ){
// Apply javascript
If (strpos ($ val ,':')){
$ A = explode (':', $ val );
If (count ($ a)> 2 ){
$ ParseStr. = ''. $ a [1].'';
} Else {
$ ParseStr. = ''. $ a [1].'';
}
} Else {
// Apply the php function
$ Array = explode ('|', $ val );
If (count ($ array)> 2 ){
$ ParseStr. = ''. $ array [2].'';
} Else {
// Convert -- Yes. multiple parameters are passed.
$ Val = str_replace ('--', $ val); // add content here
$ ParseStr. = '{$'. $ name. '.'. $ val .'}';
}
}
}
$ ParseStr. ='
';
$ ParseStr. = "n N ";
Return $ parseStr;
}

Template call demonstration:

The code is as follows:

The getTaskCategory method passes the following three parameters:
$ User ['task _ category ']
$ User ['exe _ user']
$ User ['id']

The printAccept method passes the following three parameters:
$ User ['status']
$ User ['exe _ user']
$ User ['id']

Where:

The code is as follows:

Task_category | getTaskCategory = $ user ['exe _ user'] -- $ user ['id']:


And

The code is as follows:

Status | printAccept = $ user ['exe _ user'] -- $ user ['id'], task_track: Trail

Demonstration of passing multiple parameters

I hope this article will help you with ThinkPHP framework programming.

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.