Home  >  Article  >  Backend Development  >  Detailed explanation of the use case of volist tag in thinkphp

Detailed explanation of the use case of volist tag in thinkphp

php中世界最好的语言
php中世界最好的语言Original
2018-05-19 14:59:371677browse

This time I will bring you a detailed explanation of the use case of the volist tag in thinkphp. What are the precautions when using the volist tag in thinkphp. The following is a practical case, let's take a look.

Attributes:

name (required): data template variable to be output

id (required): loop variable

offset (optional): the offset of the data to be output

length (optional): the length of the output data

key (optional): the key variable of the loop, the default value is i

mod (optional): modulo the key value, the default is 2

empty (optional): the string displayed if the data is empty

The result returned by the select method of the usual model is a two-dimensional array, which can be output directly using the volist tag.

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

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

Output even records


{$vo.name}

mod starts counting from 0, here the mod loop count is 0,1

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


{$vo.name}

mod loop count, 0,1,2,3,4 wrap when the value is 4. That is, 5 pieces of data are changed to one row.

Output loop variable


{$k}.{$vo.name}

The loop variable starts from 1 1, 2, 3, 4

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


{$i}.{$vo.name}

Comprehensive case:


checked="checked">{sh:$vo.name} 电话({sh:$vo.tel})

{sh:$mod}

Effect

I believe you will read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps for PHP to print a binary tree in Z-shaped order

PHP gets the linked list from back to front Detailed explanation of node steps

The above is the detailed content of Detailed explanation of the use case of volist tag in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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