Introduction to Volist label usage in thinkphp _php instance

Source: Internet
Author: User

Usually the Volist label is used for the result output of the query dataset (select method), and the result of the normal model's Select method is a two-dimensional array, which can be output directly using the volist tag.

You first assign a value to the template in the controller, as shown in the following example:

$User = M (' User ');
$list = $User->limit ()->select ();
$this->assign (' list ', $list);

In the template definition below, loop out the user's number and name:

<volist name= "list" id= "Vo" >
{$vo. id}:{$vo .name}<br/>
</volist>

The Volist label's Name property represents the variable name of the template assignment, so it is not optional to change in the template file. The ID represents the current loop variable and can be specified arbitrarily, 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 some of the data in the output query results, such as outputting the 5th to 15th record:

<volist name= "list" id= "Vo" offset= "5" length= ' >
{$vo. name}
</volist>

Output even records:

<volist name= "list" id= "Vo" mod= "2" >
<eq name= "mod" value= "1" >
{$vo. Name}
</eq>
</volist>

The MoD property is also used to control line wrapping for certain records, for example:

<volist name= "list" id= "Vo" mod= "5" >
{$vo. Name}
<eq name= "mod" value= "4" ><br/></eq>
</volist>

When empty, the output prompts:

<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);

And 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 you do not specify the key attribute, 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 use a key variable directly, unlike a loop variable, the key is determined by the data itself, not by the loop control, for example:

<volist name= "list" id= "Vo" >
{$key}.{ $vo. Name}
</volist>

Instead of assigning a template variable to a dataset variable in the controller, you can use a function to set the dataset directly, such as:

<volist name= ": Fun (' arg ')" id= "Vo" >
{$vo. name}
</volist>

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

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.