This article mainly introduced about thinkphp in the Volist label usage, has a certain reference value, now share to everyone, the need for friends can refer to
Usually the volist tag is used for the result output of the query dataset (select method), and the result returned by the model's Select method is a two-dimensional array, which can be output directly using the volist tag.
The template is assigned first in the controller, as shown in the following example:
$User = M (' User '), $list = $User->limit (->select); $this->assign (' list ', $list);
In the template definition as follows, loop out the user's number and name:
<volist name= "list" id= "Vo" >{$vo. id}:{$vo .name}<br/></volist>
The Name property of the volist tag represents the variable names assigned to the template, so it is not optional to change in the template file. The ID represents the current loop variable and can be arbitrarily specified, but you need to make sure that you do not conflict with the Name property, for example:
<volist name= "list" id= "Data" >{$data. id}:{$data .name}<br/></volist>
Supports the output of some of the data in the query results, such as the output of the 5th to 15th record:
<volist name= "list" id= "Vo" offset= "5" length= ' >{$vo .name}</volist>
Output even record:
<volist name= "list" id= "Vo" mod= "2" ><eq name= "mod" value= "1" >{$vo .name}</eq></volist>
MoD properties are also used to control the line breaks for a certain record, for example:
<volist name= "list" id= "Vo" mod= "5" >{$vo. Name}<eq name= "mod" value= "4" ><br/></eq></ Volist>
When empty, the output prompt:
<volist name= "list" id= "VO" empty= "temporarily no data" >{$vo. id}| {$vo .name}</volist>
The empty property does not support direct incoming HTML syntax, but can support variable output, for example:
$this->assign (' Empty ', ' <span class= ' empty ' > No data </span> '); $this->assign (' list ', $list);
Then use it in the template:
<volist name= "list" id= "Vo" empty= "$empty" >{$vo. id}| {$vo .name}</volist>
Output loop variable:
<volist name= "list" id= "Vo" key= "K" >{$k}. {$vo .name}</volist>
If the key attribute is not specified, the loop variable i is used by default, for example:
<volist name= "list" id= "Vo" >{$i}. {$vo .name}</volist>
If you want to output the index of an array, you can directly use the key variable, and the loop variable is that the key is determined by the data itself, not the loop control, for example:
<volist name= "list" id= "Vo" >{$key}. {$vo .name}</volist>
You can set a dataset directly using a function in a template without assigning a value to the template variable in the controller to an incoming dataset variable, such as:
<volist name= ": Fun (' arg ')" id= "Vo" >{$vo .name}</volist>