Usage of volist labels in Thinkphp _ php instances

Source: Internet
Author: User
Generally, the volist label is mostly used to query the result output of a dataset (select method). Generally, the result returned by the select method of the model is a two-dimensional array, you can directly use the volist label for output. Generally, the volist label is mostly used to query the result output of a dataset (select method). Generally, the result returned by the select method of the model is a two-dimensional array, you can directly use the volist label to output this information.

Assign a value to the template in the Controller, as shown in the following example:

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

The template definition is as follows:

 
  {$vo.id}:{$vo.name}
  

The name attribute of the Volist tag indicates the variable name assigned to the template. Therefore, it cannot be changed in the template file at will. Id indicates the current cyclic variable. You can specify it at will, but make sure that it does not conflict with the name attribute. For example:

 
  {$data.id}:{$data.name}
  

Some data in the query results can be output, for example, 5th ~ 15 records:

 
  {$vo.name}
 

Output even records:

 
  
   {$vo.name}
  
 

The Mod attribute is also used to control the line feed of a certain record, for example:

 
  {$vo.name}
  
   

If it is null, a prompt is displayed:

 
  
{$ Vo. id} | {$ vo. name}
 

The empty attribute does not support direct html syntax, but supports variable output. For example:

$ This-> assign ('empty', 'no data'); $ this-> assign ('LIST', $ list );

Then use the following in the template:

 
  {$vo.id}|{$vo.name}
 

Output loop variable:

 
  {$k}.{$vo.name}
 

If the key attribute is not specified, the cyclic variable I is used by default. For example:

 
  {$i}.{$vo.name}
 

If you want to output the index of an array, you can directly use the key variable. Unlike the Loop Variable, this key is determined by the data itself, rather than being controlled cyclically. For example:

 
  {$key}.{$vo.name}
 

In the template, you can directly use functions to set the dataset without assigning values to the template variables in the Controller. For example:

 
  {$vo.name}
 

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.