The html: list tag in thinkphp passes multiple parameter instances

  • 2021-07-22 09:25:54
  • OfStack

This article examples about thinkphp html: list tag transmission of multiple parameters problem solutions, to share for your reference. The specific analysis is as follows:

This change is valid for thinkphp 2.0, and thinkphp 3.0 is not tested.
Mainly modify the _ list method of this file./Thinkphp/Lib/Think/Template/Taglib/TabLibHtml. class. php

Comment the part of code with new content is newly added
Mainly by splitting multiple parameters (which will be automatically replaced with,)

public function _list($attr)
{
        $tag        = $this->parseXmlAttr($attr,'list');
        $id         = $tag['id'];                       // Forms ID
        $datasource = $tag['datasource'];               // Data sources displayed in the list VoList Name
        $pk         = empty($tag['pk'])?'id':$tag['pk'];// Primary key name, default to 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 function actions
        $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 a list of functions
        }
        if(substr($tag['show'],0,1)=='$') {
            $show   = $this->tpl->get(substr($tag['show'],1));
        }else {
            $show   = $tag['show'];
        }
        $show       = explode(',',$show);                // List displays a list of fields
        // Count 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 = "<!-- Think System List Component Begins -->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" >';
        // List the fields 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 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) {// Displays 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 to '.$showname[2].'{$sortType} ">'.$showname[0].'<eq name="order" value="'.$property[0].'" ><img xsrc="/Public/images/{$sortImg}.gif" width="12" height="17" border="0" align="absmiddle"></eq></a></th>';
            }else{
                $parseStr .= $showname[0].'</th>';
            }
        }
        if(!empty($action)) {// If you specify a display action function column
            $parseStr .= '<th > Operation </th>';
        }
        $parseStr .= '</tr>';
        $parseStr .= '<volist name="'.$datasource.'" id="'.$name.'" ><tr class="row" '; // Support the color change of mouse moving unit line The specific method is js Definition in
        if(!empty($checkbox)) {
            $parseStr .= 'onmouseover="over(event)" onmouseout="out(event)" onclick="change(event)" ';
        }
        $parseStr .= '>';
        if(!empty($checkbox)) {// If you need to display checkbox Is displayed at the beginning of each line checkbox
            $parseStr .= '<td><input type="checkbox" name="key" value="{$'.$name.'.'.$pk.'}"></td>';
        }
        if(!empty($key)) {
            $parseStr .= '<td>{$i}</td>';
        }
        foreach($fields as $field) {
            // Display defined list fields
            $parseStr   .=  '<td>';
            if(!empty($field[2])) {
                // Support list field linking function The specific method consists of JS Function realization
                $href = explode('|',$field[2]);
                if(count($href)>1) {
                    // Specify the field value of the link pass
                    // Support multiple field passing
                    $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 transfer 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 , Pass multiple parameters
                    $property[1] = str_replace('--',',',$property[1]);// Here is the new content
                    $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])) {// Displays the specified function item
                $parseStr .= '<td>';
                foreach($actionlist as $val) {
                     // Application 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{
                        // Application php Function
      $array = explode('|',$val);
      if(count($array)>2) {
       $parseStr .= ' <a xhref="javascript:'.$array[1].'('{$'.$name.'.'.$array[0].'}')">'.$array[2].'</a>&nbsp;';
      }else{
                            // Conversion -- For , Pass multiple parameters
                            $val = str_replace('--',',',$val);// Here is the new content
       $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 End of system list component -->n";
        return $parseStr;
}

Template invocation demo:

<html:list id="checkList" name="user" style="list" checkbox="true" action="true" datasource="list" show="id: Numbering ,task_title: Task title :edit,task_type|getTaskType: Task type ,task_category|getTaskCategory=$user['exe_user']--$user['id']: Column to which ,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: Tracking " />

Method getTaskCategory passes three parameters in the following order:
$user['task_category']
$user['exe_user']
$user['id']

Method printAccept passes three parameters in the following order:
$user['status']
$user['exe_user']
$user['id']

Among them:

task_category|getTaskCategory=$user['exe_user']--$user['id']:

And
status|printAccept=$user['exe_user']--$user['id'],task_track: Tracking 
To pass a demonstration of multiple parameters

I hope this article is helpful to everyone's ThinkPHP framework programming.


Related articles: