PHP development framework YiiFramework tutorial (30) Zii component-ListView example

Source: Internet
Author: User
PHP development framework YiiFramework tutorial (30) Zii component-ListView example

CListView can be used to display the list. CListView supports displaying the list records using a custom View template. Therefore, you can flexibly display the data table, which is a bit like the Android ListView :-).

CListView supports paging and sorting, and supports AJAX implementation to improve page response performance. To use CListView, you must use DataProvider. generally, CActiveDataProvider is used.

In this example, the Yii Framework Development Tutorial (26) database-Active Record example is modified. however, to display the page, we use the Customer database table, with 10 records displayed on each page.

Modify the default view protected/views/site/index. php and use the ListView component.

Widget

('Zii. widgets. clistview', array (
'Dataprovider' => $ dataProvider,
'Ajaxupdate' => false,
'Template' => '{sorter} {pager} {summary} {items} {pager }',
'Itemview' => '_ view ',
'Pager' => array (
'Maxbuttoncount' => '7 ',
),
'Sortableattribuckets' => array (
'Firstname ',
'Lastname ',
'Country ',
),
);?>

The template displayed on the parameter template configuration page. the supported parameters include {summary}, {sorter}, {items}, and {pager}, which correspond to the ListView summary, sorting, and list items respectively, paging control.

The itemView parameter indicates that the View corresponding to each list item is displayed. This example uses site/_ view. php, which is defined as follows:



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

GetAttributeLabel ('Company');?> :
Company);?>



GetAttributeLabel ('address');?> :
Format-> formatUrl ($ data-> Address);?>



GetAttributeLabel ('country');?> :
Country);?>



GetAttributeLabel ('email ');?> :
Format-> formatEmail ($ data-> Email);?>



Then modify the indexAction method of SiteController:

Public function actionIndex ()
{

$ DataProvider = new CActiveDataProvider ('customer', array (
'Pagination' => array (
'Pagesize' => 10,
'Pagevar '=> 'Page ',
),
'Sort '=> array (
'Defaultorder' => 'lastname ',
),
));
$ This-> render ('index', array (
'Dataprovider' => $ dataProvider,
));
}

The result is as follows:

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.