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
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
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. ='
No | ';}Foreach ($ fields as $ field) {// display the specified field$ Property = explode ('|', $ field [0]);$ Showname = explode ('|', $ field [1]);If (isset ($ showname [1]) {$ ParseStr. ='
'; } Else { $ ParseStr. =' |
'; } $ Showname [2] = isset ($ showname [2])? $ Showname [2]: $ showname [0]; If ($ sort ){ $ ParseStr. = ''. $ showname [0].' | ';} Else {$ ParseStr. = $ showname [0].'';}}If (! Empty ($ action) {// If you specify to display the Operation Function Column$ ParseStr. ='
Operation | ';}$ ParseStr. ='
';$ ParseStr. ='
If (! Empty ($ checkbox )){$ ParseStr. = 'onmouseover = "over (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. ='
{$ I} | ';}Foreach ($ fields as $ field ){// Display the defined list fields$ ParseStr. ='
'; 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. =' | ';}If (! Empty ($ action) {// display operationIf (! Empty ($ actionlist [0]) {// display the specified function item$ 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. =' | ';// Echo $ parseStr;// Exit ();}}$ ParseStr. ='
|
';
$ ParseStr. = "n N ";
Return $ parseStr;
}
Template call Demonstration:
The Code is as follows: