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: