In thinkphp, multiple parameters are passed through the html: list tag.

Source: Internet
Author: User
Tags foreach explode sort

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 red code is newly added.

Multiple parameters are separated by commas ,)

The code is as follows: Copy code

 

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 = "<! -- Think system list component start --> n ";
$ ParseStr. = '<table id = "'. $ id. '" class = "'. $ style. '" cellpadding = 0 cellspacing = 0> ';
$ ParseStr. = '<tr> <td height = "5" colspan = "'. $ colNum. '"class =" topTd "> </td> </tr> ';
$ ParseStr. = '<tr class = "row"> ';
// 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. = '<th width = "8"> <input type = "checkbox" id = "check" onclick = "CheckAll (''. $ id. '')"> </th> ';
        }
If (! Empty ($ key )){
$ ParseStr. = '<th width = "12"> No </th> ';
        }
Foreach ($ fields as $ field) {// display the specified field
$ Property = explode ('|', $ field [0]);
$ Showname = explode ('|', $ field [1]);
If (isset ($ showname [1]) {
$ ParseStr. = '<th width = "'. $ showname [1]. '"> ';
} Else {
$ ParseStr. = '<th> ';
            }
$ Showname [2] = isset ($ showname [2])? $ Showname [2]: $ showname [0];
If ($ sort ){
$ ParseStr. = '<a xhref = "javascript: sortBy (''. $ property [0]. '', '{$ sort }',''. ACTION_NAME. '')" title = "according '. $ showname [2]. '{$ sortType} "> '. $ showname [0]. '<eq name = "order" value = "'. $ property [0]. '"> </eq> </a> </th> ';
} Else {
$ ParseStr. = $ showname [0]. '</th> ';
            }

        }
If (! Empty ($ action) {// if you specify to display the operation function column
$ ParseStr. = '<th> Operation </th> ';
        }

$ ParseStr. = '</tr> ';
$ ParseStr. = '<volist name = "'. $ datasource. '"id = "'. $ name. '"> <tr class =" row "'; // you can move the cell line color with the mouse. The specific method is defined in js.
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. = '<td> <input type = "checkbox" name = "key" value = "{$ '. $ name. '. '. $ pk. '} "> </td> ';
        }
If (! Empty ($ key )){
$ ParseStr. = '<td >{$ I} </td> ';
        }
Foreach ($ fields as $ field ){
// Display the defined list fields
$ ParseStr. = '<td> ';
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. = '<a xhref = "javascript:'. $ href [0]. '('. implode (',', $ temp). ')"> ';
} Else {
$ ParseStr. = '<a xhref = "javascript :'. $ href [0]. '(' {$ '. $ name. '. '. $ href [1]. '| addslashes}') "> ';
                    }
} Else {
// If no default serial number is specified
$ ParseStr. = '<a xhref = "javascript :'. $ field [2]. '(' {$ '. $ name. '. '. $ pk. '| addslashes}') "> ';
                }
            }
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]);
$ ParseStr. = '{$'. $ name. '.'. $ property [0]. '|'. $ property [1]. '}';
} Else {
$ ParseStr. = '{$'. $ name. '.'. $ field [0]. '}';
                }
            }
If (! Empty ($ field [2]) {
$ ParseStr. = '</a> ';
            }
$ ParseStr. = '</td> ';

        }
If (! Empty ($ action) {// Display operation
If (! Empty ($ actionlist [0]) {// display the specified function item
$ ParseStr. = '<td> ';
Foreach ($ actionlist as $ val ){
// Apply javascript
If (strpos ($ val ,':')){
$ A = explode (':', $ val );
If (count ($ a)> 2 ){
$ ParseStr. = '<a xhref = "javascript :'. $ a [0]. '(' {$ '. $ name. '. '. $ a [2]. '}') "> '. $ a [1]. '</a> & nbsp ;';
} Else {
$ ParseStr. = '<a xhref = "javascript :'. $ a [0]. '(' {$ '. $ name. '. '. $ pk. '}') "> '. $ a [1]. '</a> & nbsp ;';
      }
} Else {
// Apply the php function
$ Array = explode ('|', $ val );
If (count ($ array)> 2 ){
$ ParseStr. = '<a xhref = "javascript :'. $ array [1]. '(' {$ '. $ name. '. '. $ array [0]. '}') "> '. $ array [2]. '</a> & nbsp ;';
} Else {
                          // Convert -- Yes. Multiple parameters are passed.
$ Val = str_replace ('--', $ val );
$ ParseStr. = '{$'. $ name. '.'. $ val. '} & nbsp ;';
      }
     }
                }
$ ParseStr. = '</td> ';
// Echo $ parseStr;
// Exit ();
            }
        }
$ ParseStr. = '</tr> </volist> <tr> <td height = "5" colspan = "'. $ colNum. '"class =" bottomTd "> </td> </tr> </table> ';
$ ParseStr. = "n <! -- Think system list component ended --> n ";
Return $ parseStr;
    } 


 
Template call demonstration:

The method marked in red shows how to pass multiple parameters.

The getTaskCategory method passes three parameters in the order of $ user ['task _ category '] $ user ['exe _ user'] $ user ['id'].

In the printAccept method, the order of the three parameters is $ user ['status'] $ user ['exe _ user'] $ user ['id'].

The code is as follows: Copy code

 

<Html: list id = "checkList" name = "user" style = "list" checkbox = "true" action = "true" datasource = "list" show = "id: no. task_title: task Title: edit, task_type | getTaskType: task type,Task_category | getTaskCategory = $ user ['exe _ user'] -- $ user ['id']:Topic, hope_time | toDate = 'Y-m-d H # I ': Expected completion time, process_rate | printRate: current progress, exe_user | getUserName: Handler, status | getTaskStatus: status "actionlist ="Status | printAccept = $ user ['exe _ user'] -- $ user ['id'], task_track: Trail"/>

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.