CListView can be used to display lists. CListView supports using custom View templates to display list records, so it can display data tables very flexibly. This is a bit like Android's ListView:-).
CListView supports paging and sorting. Paging and sorting support the use of AJAX to improve the response performance of the page. The use of CListView requires a DataProvider, usually using CActiveDataProvider.
This example modifies the database-Active Record example of Yii Framework Development Tutorial (26), but in order to display paging, we use the Customer database table to display 10 records per 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',), 'sortableAttributes'=>array('FirstName','LastName','Country',),)); ?>
Parameter template Configure the template displayed on the page. The supported parameters are {summary}, {sorter}, {items} and {pager}, which respectively correspond to the summary, sorting, list items and paging control of ListView.
The parameter itemView specifies the View display corresponding to each list item. This example uses site/_view.php, 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 display result is as follows:
The above is the content of the PHP development framework Yii Framework tutorial (30) Zii component-ListView example. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!