Home php教程 php手册 Yii Framework 开发教程Zii组件-ListView 示例

Yii Framework 开发教程Zii组件-ListView 示例

Jun 13, 2016 am 10:54 AM
framework yii Can develop Tutorial show Example components

CListView可以用来显示列表,CListView支持使用自定义的View模板显示列表的的记录,因此可以非常灵活的显示数据的表,这点有点像Android的ListView:-)。

 

CListView 支持分页和排序,分页和排序支持使用AJAX实现从而可以提高页面的响应性能。CListView的使用需要通过DataProvider,通常是使用CActiveDataProvider。

 

本例修改Yii Framework 开发教程(26) 数据库-Active Record示例,不过为了显示分页,我们使用Customer数据库表,每页显示10条记录。

 

修改缺省的视图protected/views/site/index.php,使用ListView组件。

 

 

[php]  

widget('zii.widgets.CListView', array(  

    'dataProvider'=>$dataProvider,  

    'ajaxUpdate'=>false,  

    'template'=>'{sorter}{pager}{summary}{items}{pager}',  

    'itemView'=>'_view',  

    'pager'=>array(  

                'maxButtonCount'=>'7',  

                ),  

            'sortableAttributes'=>array(  

                'FirstName',  

                'LastName',  

                'Country',  

                ),  

)); ?>  

 

widget('zii.widgets.CListView', array(

'dataProvider'=>$dataProvider,

'ajaxUpdate'=>false,

'template'=>'{sorter}{pager}{summary}{items}{pager}',

'itemView'=>'_view',

'pager'=>array(

'maxButtonCount'=>'7',

),

'sortableAttributes'=>array(

'FirstName',

'LastName',

'Country',

),

)); ?>

 

参数template 配置页面显示的模板,支持的参数有 {summary}, {sorter}, {items} 和{pager},分别对应于ListView的汇总,排序,列表项,分页控制。

参数itemView 指明每个列表项对应的View显示。本例使用site/_view.php ,定义如下:

 

 

 

[php]  

 

  

FirstName . ' ' . $data->LastName);?>

 

  

getAttributeLabel('Company')); ?>:  

Company); ?>  


 

  

getAttributeLabel('Address')); ?>:  

format->formatUrl($data->Address); ?>  


 

  

getAttributeLabel('Country')); ?>:  

Country); ?>  


 

  

getAttributeLabel('Email')); ?>:  

format->formatEmail($data->Email); ?>  


 

  

 

 

 

FirstName . ' ' . $data->LastName);?>

 

getAttributeLabel('Company')); ?>:

Company); ?>


 

getAttributeLabel('Address')); ?>:

format->formatUrl($data->Address); ?>


 

getAttributeLabel('Country')); ?>:

Country); ?>


 

getAttributeLabel('Email')); ?>:

format->formatEmail($data->Email); ?>


 

 

然后修改SiteController的indexAction方法:

 

 

 

[php]  

public function actionIndex()  

{  

  

    $dataProvider=new CActiveDataProvider('Customer', array(  

        'pagination'=>array(  

            'pageSize'=>10,  

            'pageVar'=>'page',  

        ),  

                'sort'=>array(  

                    'defaultOrder'=>'Lastname',  

                    ),  

                ));  

    $this->render('index',array(  

        'dataProvider'=>$dataProvider,  

        ));  

}  

 

public function actionIndex()

{

 

$dataProvider=new CActiveDataProvider('Customer', array(

'pagination'=>array(

'pageSize'=>10,

'pageVar'=>'page',

),

'sort'=>array(

'defaultOrder'=>'Lastname',

),

));

$this->render('index',array(

'dataProvider'=>$dataProvider,

));

}

 

 

 

显示结果如下:

 

 

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

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

Exploring Go language front-end technology: a new vision for front-end development Exploring Go language front-end technology: a new vision for front-end development Mar 28, 2024 pm 01:06 PM

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

A simple tutorial on converting full-width English letters to half-width letters A simple tutorial on converting full-width English letters to half-width letters Mar 25, 2024 pm 09:21 PM

When using a computer to input English, sometimes we encounter the difference between full-width English letters and half-width English letters. Full-width English letters refer to the characters input by pressing the Shift key and the English letter key combination when the input method is Chinese mode. They occupy a full-width character width. Half-width English letters refer to characters input directly when the input method is English mode, and they occupy half a character width. In some cases, we may need to convert full-width English letters to half-width letters. Here is a simple tutorial: First, open a text editor or any

See all articles