The example of this article tells about the thinkphp of the Html:list label transmission of multiple parameters of the solution, shared for everyone to reference. The specific analysis is as follows:
This change is valid for the Thinkphp 2.0 version and thinkphp 3.0 is not tested.
Main modification of this file/thinkphp/lib/think/template/taglib/tablibhtml.class.php _list method
Note The code part that has the new additions is the newly added
Mainly through--split multiple arguments (automatically replaced with,)
Copy Code code as follows:
Public Function _list ($attr)
{
$tag = $this->parsexmlattr ($attr, ' list ');
$id = $tag [' id ']; Table ID
$datasource = $tag [' datasource ']; The data source volist name displayed in the list
$PK = Empty ($tag [' PK '])? ' ID ': $tag [' PK '];//primary key name, default 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 feature actions
$key =!empty ($tag [' key ']) True:false;
$sort = $tag [' Sort ']== ' false ' false:true;
$checkbox = $tag [' checkbox ']; Whether to display a checkbox
if (Isset ($tag [' actionlist '])) {
$actionlist = Explode (', ', Trim ($tag [' actionlist '])); Specify a list of features
}
if (substr ($tag [' show '],0,1] = = ' $ ') {
$show = $this->tpl->get (substr ($tag [' Show '],1)];
}else {
$show = $tag [' Show '];
}
$show = Explode (', ', $show); List Display field List
Calculate the number of columns in a table
$colNum = count ($show);
if (!empty ($checkbox)) $colNum + +;
if (!empty ($action)) $colNum + +;
if (!empty ($key)) $colNum + +;
Show start
$PARSESTR = "<!--the list component starts-->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 ' > ';
The fields that the list needs to display
$fields = Array ();
foreach ($show as $val) {
$fields [] = Explode (': ', $val);
}
if (!empty ($checkbox) && ' true ' ==strtolower ($checkbox)) {//If you specify that you want to display the checkbox column
$parseStr. = ' <th width= ' 8 ><input type= checkbox ' id= ' Check ' onclick= ' Checkall ('. $id. ') ></th> ';
}
if (!empty ($key)) {
$parseStr. = ' <th width= ' >No</th> ';
}
foreach ($fields as $field) {//Show specified fields
$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= "in accordance with '. $showname [2]. ' {$sortType} ">" $showname [0]. ' <eq name= "Order" value= "'. $property [0]. '" ></eq></a></th>;
}else{
$parseStr. = $showname [0]. ' </th> ';
}
}
if (!empty ($action)) {//If the Display Action feature column is specified
$parseStr. = ' <th > Operation </th> ';
}
$parseStr. = ' </tr> ';
$parseStr. = ' <volist name= '. $datasource. ' id= '. $name. ' "><tr class=" Row "; Support Mouse mobile cell line Color change specific method in JS definition
if (!empty ($checkbox)) {
$parseStr. = ' onmouseover= ' Over (event) "onmouseout=" Out (event) "onclick=" Change (event) "";
}
$parseStr. = ' > ';
if (!empty ($checkbox)) {//checkbox is displayed at the beginning of each line if a checkbox is required
$parseStr. = ' <td><input type= checkbox ' name= ' key ' value= ' {$ '. $name '. $pk. '} ' ></td> ';
}
if (!empty ($key)) {
$parseStr. = ' <td>{$i}</td> ';
}
foreach ($fields as $field) {
Display a defined list field
$parseStr. = ' <td> ';
if (!empty ($field [2])) {
Support List field Link function concrete method is realized by JS function
$href = Explode (' | ', $field [2]);
if (count ($href) >1) {
Specify the value of the field that the link passes
Supports multiple field passes
$array = explode (' ^ ', $href [1]);
if (count ($array) >1) {
foreach ($array as $a) {
$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 you do not specify a default pass number value
$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) {
Conversion--for, passing multiple parameters
$property [1] = Str_replace ('--', ', ', $property [1]); Here's what's new
$parseStr. = ' {$ '. $name. '. $property [0]. ' | '. $property [1]. '} ';
}else {
$parseStr. = ' {$ '. $name. '. $field [0]. '} ';
}
}
if (!empty ($field [2])) {
$parseStr. = ' </a> ';
}
$parseStr. = ' </td> ';
}
if (!empty ($action)) {//Display function operation
if (!empty ($actionlist [0])) {//Display the specified feature 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> ';
}else {
$parseStr. = ' <a xhref= ' javascript: '. $a [0]. ' (' {$ '. $name. '. ') $pk. '} ') ' > '. $a [1]. ' </a> ';
}
}else{
Apply PHP functions
$array = Explode (' | ', $val);
if (count ($array) >2) {
$parseStr. = ' <a xhref= ' javascript: '. $array [1]. ' (' {$ '. $name. '. ') $array [0]. '} ' > '. $array [2]. ' </a> ';
}else{
Conversion--for, passing multiple parameters
$val = Str_replace ('--', ', ', $val);//Here's what's new
$parseStr. = ' {$ '. $name. '. $val. '} ';
}
}
}
$parseStr. = ' </td> ';
Echo $parseStr;
Exit ();
}
}
$parseStr. = ' </tr></volist><tr><td height= ' 5 "colspan=" '. $colNum. ' "Class= bottomtd" ></ Td></tr></table> ';
$parseStr. = "n<!--the System list component End-->n";
return $parseStr;
}
Template Invocation Demo:
Copy Code code as follows:
Copy Code code as follows:
task_category|gettaskcategory= $user [' Exe_user ']--$user [' ID ']:
And
Copy Code code as follows:
status|printaccept= $user [' Exe_user ']--$user [' ID '],TASK_TRACK: Tracking
Demo for passing multiple parameters
I hope this article will be helpful to everyone's thinkphp framework program design.