CListView can be used to display lists, CListView support the use of custom view templates to display lists of records, so it is very flexible to display the table of data, which is a bit like the Android ListView:-).
CListView supports paging and sorting, paging and sorting support using AJAX implementations to improve page responsiveness. The use of CListView needs to be done through dataprovider, usually using Cactivedataprovider.
This example modifies the Yii Framework development tutorial (26) database-active The record example, but in order to display pagination, we use the Customer database table, each page displays 10 records.
Modify the default view protected/views/site/index.php and use the ListView component.
<?php $this->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 ',
),)
;?>
Parameter template Configuration page display template, supported parameters are {summary}, {sorter}, {items} and {pager}, corresponding to ListView totals, sorting, list items, paging control.
The parameter Itemview indicates the view display for each list item. This example uses site/_view.php, which is defined as follows:
<center class= "item" >
Then modify the Sitecontroller Indexaction method:
Public Function Actionindex ()
{
$dataProvider =new cactivedataprovider (' Customer ', Array (
' pagination ' = >array (
' pageSize ' =>10,
' pagevar ' => ' page '
),
' sort ' =>array (
' defaultorder ' = > ' Lastname ',))
;
$this->render (' index ', array (
' Dataprovider ' => $dataProvider,
));
}