Home > Backend Development > PHP Tutorial > Introduction to the usage of volist tag in Thinkphp_PHP tutorial

Introduction to the usage of volist tag in Thinkphp_PHP tutorial

WBOY
Release: 2016-07-13 10:24:43
Original
1251 people have browsed it

Usually the volist tag is mostly used to output the results of querying the data set (select method). Usually the result returned by the select method of the model is a two-dimensional array, for which the volist tag can be used directly for output.

First 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);
Copy after login

The template is defined as follows, and the user’s number and name are output in a loop:

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

The name attribute of the Volist tag represents the variable name assigned by the template, so it cannot be changed at will in the template file. id represents the current loop variable, which can be specified at will, but you need to make sure not to conflict with the name attribute, for example:

<volist name="list" id="data">
{$data.id}:{$data.name}<br/>
</volist>
Copy after login

Supports outputting part of the data in the query results, for example, outputting the 5th to 15th records:

<volist name="list" id="vo" offset="5" length='10'>
{$vo.name}
</volist>
Copy after login

Output even records:

<volist name="list" id="vo" mod="2" >
<eq name="mod" value="1">
{$vo.name}
</eq>
</volist>
Copy after login

Mod attribute is also used to control the line wrapping of certain records, for example:

<volist name="list" id="vo" mod="5" >
{$vo.name}
<eq name="mod" value="4"><br/></eq>
</volist>
Copy after login
When

is empty, output prompt:

<volist name="list" id="vo" empty="暂时没有数据" >
{$vo.id}|{$vo.name}
</volist>
Copy after login
The

empty attribute does not support direct passing of HTML syntax, but can support variable output, for example:

$this->assign('empty','<span class="empty">没有数据</span>');
$this->assign('list',$list);
Copy after login

Then use in the template:

<volist name="list" id="vo" empty="$empty" >
{$vo.id}|{$vo.name}
</volist>
Copy after login

Output loop variable:

<volist name="list" id="vo" key="k" >
{$k}.{$vo.name}
</volist>
Copy after login

If the key attribute is not specified, the loop variable i is used by default, for example:

<volist name="list" id="vo" >
{$i}.{$vo.name}
</volist>
Copy after login

If you want to output the index of the array, you can use the key variable directly. Unlike the loop variable, the key is determined by the data itself, not controlled by the loop, for example:

<volist name="list" id="vo" >
{$key}.{$vo.name}
</volist>
Copy after login

You can directly use functions to set data sets in templates, without assigning values ​​to template variables in the controller and passing in data set variables, such as:

<volist name=":fun('arg')" id="vo">
{$vo.name}
</volist>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825337.htmlTechArticleUsually the volist tag is mostly used to query the result output of the data set (select method), usually the result returned by the select method of the model is a two-dimensional array, for which you can directly use the volist tag...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template