CListView can be used to display lists, CListView supports 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, pagination and sorting support using AJAX implementations to improve page responsiveness. The use of CListView is required through dataprovider, usually using Cactivedataprovider.
This example modifies the Yii Framework development tutorial (26) Database-active record example, but in order to display pagination, we use the Customer database table, which shows 10 records per page.
Modify the default view protected/views/site/index.php, using 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 ',),);?>
The Parameter Template Configuration page displays templates that support the parameters {summary}, {sorter}, {items}, and {pager}, respectively, corresponding to the ListView summary, Sort, list item, pagination control.
The parameter Itemview indicates the view display for each list item. 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 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,));}
The results appear as follows:
The above is the PHP Development Framework Yii Framework Tutorial (a) Zii component-listview sample content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!