search
Homephp教程php手册Thinkphp中的volist标签用法简介

通常volist标签多用于查询数据集(select方法)的结果输出,通常模型的select方法返回的结果是一个二维数组,对此可以直接使用volist标签进行输出

通常volist标签多用于查询数据集(select方法)的结果输出,通常模型的select方法返回的结果是一个二维数组,对此可以直接使用volist标签进行输出。

在控制器中首先对模版赋值,如下例所示:

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

在模版定义如下,循环输出用户的编号和姓名:

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

Volist标签的name属性表示模板赋值的变量名称,因此不可随意在模板文件中改变。id表示当前的循环变量,可以随意指定,但需要确保不要和name属性冲突,例如:

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

支持输出查询结果中的部分数据,例如输出其中的第5~15条记录:

{$vo.name}

输出偶数记录:

{$vo.name}

Mod属性还用于控制一定记录的换行,例如:

{$vo.name}

为空的时候输出提示:

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

empty属性不支持直接传入html语法,但可以支持变量输出,例如:

$this->assign('empty','没有数据'); $this->assign('list',$list);

然后在模板中使用:

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

输出循环变量:

{$k}.{$vo.name}

如果没有指定key属性的话,默认使用循环变量i,例如:

{$i}.{$vo.name}

如果要输出数组的索引,可以直接使用key变量,和循环变量不同的是,这个key是由数据本身决定,而不是循环控制的,例如:

{$key}.{$vo.name}

模板中可以直接使用函数设定数据集,而不需要在控制器中给模板变量赋值传入数据集变量,,如:

{$vo.name}

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)