ThinkPHP template cyclically outputs Volist tag usage example _ php instance

Source: Internet
Author: User
This article mainly introduces the usage of the Volist tag generated by the ThinkPHP template in a loop, and analyzes the Volist tag function, usage methods, and related precautions in detail based on the instance form, for more information about how to use the ThinkPHP template to generate a Volist tag, see the following example. We will share this with you for your reference. The details are as follows:

The volist tag is used to output a dataset or multi-dimensional array cyclically in the template.

Volist tag

In the module operation, the select () method returns a two-dimensional array, which can be output directly using volist:

 
  
User name: {$ vo ['username']}
  
Email: {$ vo ['email ']}
Registration Time: {$ vo ['regdate'] | date = "Y-m-d H: I ",###}

To output multi-dimensional arrays, see the ThinkPHP template Volist label nested loop output multi-dimensional array method.

Note: The name Attribute Value list (name = "list") cannot be changed at will. It must correspond to the template assignment instruction in the operation:

$this->assign( "list", $list );

Id indicates the cyclic variable, which can be specified at will, but cannot conflict with the name attribute.

Output part of data

If you want to output part of the data in the result set, you must specify the offset (Data Pointer) and length (number of data records) attributes.

Output 5th ~ 14 records:

 
  
User name: {$ vo ['username']}
  
Email: {$ vo ['email ']}
Registration Time: {$ vo ['regdate'] | date = "Y-m-d H: I ",###}

Output odd/even records

The mod parameter in volist is equivalent to specifying a frequency. The system calculates the remainder (the % operator in PHP) of the mod parameter value in the current actual record. Combined with tags (such as eq tags), you can control the output data or data display format based on the frequency.

Example 1: output an even number of records:

 
  
   
User name: {$ vo ['username']}
   
Email: {$ vo ['email ']}
Registration Time: {$ vo ['regdate'] | date = "Y-m-d H: I ",###}

Example 2: Output all records, but show different background colors in the table on the different rows:

 
  
   
Style = "background-color: # FFF ;">
  
 
 
 
I am a cell content I am also a cell content

Tip: in actual use, you can flexibly set the mod parameter value, not only for parity.

Output Loop Variable

Specify the number of variables used by the key attribute to output the loop (not the primary key id of the data table ):

 
  
SN: {$ k}
  
User name: {$ vo ['username']}
Email: {$ vo ['email ']}
Registration Time: {$ vo ['regdate'] | date = "Y-m-d H: I ",###}

Output array index

Use the $ key variable directly to output the array index:

 
  
Array key: {$ key}
  
User name: {$ vo ['username']}
Email: {$ vo ['email ']}
Registration Time: {$ vo ['regdate'] | date = "Y-m-d H: I ",###}

Prompt

Different from the output loop variable, the key value depends on the data, rather than the volist loop output.

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.