Introduction to the usage of volist tags in thinkphp (Result output of query Datasets (select method))

Source: Internet
Author: User

Reference URL: http://camnpr.com/archives/1515.html

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:

View Sourceprint?
1 $User = M (' User ');

2 $list = $User->limit ()->select ();

3 $this->assign (' list ', $list);
In the template definition as follows, loop out the user's number and name:

View Sourceprint?
1 <volist name= "list" id= "Vo" >

2 {$vo. id}:{$vo. Name}

3

4 </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:

View Sourceprint?
1 <volist name= "list" id= "Data" >

2 {$data. id}:{$data. Name}

3

4 </volist>
Supports the output of some of the data in the query results, such as the output of the 5th to 15th record:

View Sourceprint?
1 <volist name= "list" id= "Vo" offset= "5" length= ' >

2 {$vo. Name}

3 </volist>
Output even record:

View Sourceprint?
1 <volist name= "list" id= "Vo" mod= "2" >

2 <eq name= "mod" value= "1" >

3 {$vo. Name}

4 </eq>

5 </volist>
MoD properties are also used to control the line breaks for a certain record, for example:

View Sourceprint?
1 <volist name= "list" id= "Vo" mod= "5" >

2 {$vo. Name}

3 <eq name= "mod" value= "4" >

4 </eq>

5 </volist>
When empty, the output prompt:

View Sourceprint?
1 <volist name= "list" id= "VO" empty= "temporarily no data" >

2 {$vo. id}| {$vo. Name}

3 </volist>
The empty property does not support direct incoming HTML syntax, but can support variable output, for example:

View Sourceprint?
1 $this->assign (' Empty ', ' <span class= ' empty ' > No data </span> ');

2 $this->assign (' list ', $list);
Then use it in the template:

View Sourceprint?
1 <volist name= "list" id= "Vo" empty= "$empty" >

2 {$vo. id}| {$vo. Name}

3 </volist>
Output loop variable:

View Sourceprint?
1 <volist name= "list" id= "Vo" key= "K" >

2 {$k}. {$vo. Name}

3 </volist>
If the key attribute is not specified, the loop variable i is used by default, for example:

View Sourceprint?
1 <volist name= "list" id= "Vo" >

2 {$i}. {$vo. Name}

3 </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:

View Sourceprint?
1 <volist name= "list" id= "Vo" >

2 {$key}. {$vo. Name}

3 </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:

View Sourceprint?
1 <volist name= ": Fun (' arg ')" id= "Vo" >

2 {$vo. Name}

3 </volist>

Introduction to the usage of volist tags in thinkphp (Result output of query Datasets (select method))

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.