This article describes the thinkphp template looping output volist label usage. Share to everyone for your reference, as follows:
The Volist label is used to loop the output dataset or multidimensional array in the template.
Volist Label
In the module operation, the Select () method returns a two-dimensional array that can be directly output with volist:
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}
If you want to output a multidimensional array, see the thinkphp template volist label nested loop output multidimensional Array method
Note: The property value of Name list (name= "list") cannot be changed arbitrarily, it needs to correspond with the template assignment instruction in the operation:
$this->assign ("list", $list);
The ID represents a looping variable, which can be arbitrarily specified, but must not conflict with the Name property.
Output partial data
If you want to output part of the data in the result set, you need to specify the offset (data pointer) with the length (number of data data bars) property.
Output 5th to 14th record:
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}
Output odd/even record
The MoD parameter in Volist is equivalent to specifying a frequency, and the system will calculate the current actual record for the MoD parameter value (% operator in PHP). In conjunction with a judgment label (such as an EQ tag), the output data or data display format can be controlled according to the frequency.
Example 1, output even record:
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}
Example 2, the output of all records, but let the table interlaced display different background color example:
<>
Style= "Background-color: #FFF;" >
I am a cell content |
I am also a cell content |
Hint: The value of mod parameters can be set flexibly in actual use, not just parity.
Output loop variable
Specifies the number of times the key property is used to output the loop (note that it is not a data table primary key ID):
Sequence number: {$k}
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}
Output array index
Use $key variables directly for the output array index:
Array key:{$key}
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}
Tips
Unlike the output loop variable, this key value is determined by the data itself, not by the volist loop output.
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.