Home > Backend Development > PHP Tutorial > Yii Framework Development Tutorial Zii Component-ListView Example_PHP Tutorial

Yii Framework Development Tutorial Zii Component-ListView Example_PHP Tutorial

WBOY
Release: 2016-07-14 10:07:38
Original
781 people have browsed it

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 responsiveness of the page. The use of CListView requires a 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 to display 10 records per page.
Modify the default view protected/views/site/index.php and use the ListView component.
[php]
widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'ajaxUpdate'=>false,
'template'=>'{sorter}{pager}{summary}{items}{pager}',
'itemView'=>'_view',
'pager'=>array(
                                                                                                                                                                                                 
        ),  
'sortableAttributes'=>array(
            'FirstName',  
'LastName',
'Country',
        ),  
)); ?>
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 configures 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:
[php]

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

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

getAttributeLabel('Address')); ?>:
format->formatUrl($data->Address); ?>

getAttributeLabel('Country')); ?>:
Country); ?>

getAttributeLabel('Email')); ?>:
format->formatEmail($data->Email); ?>

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

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

 
getAttributeLabel('Address')); ?>:
format->formatUrl($data->Address); ?>

 
getAttributeLabel('Country')); ?>:
Country); ?>

 
getAttributeLabel('Email')); ?>:
format->formatEmail($data->Email); ?>

 
 
然后修改SiteController的indexAction方法:
 
 
 
[php]  
public function actionIndex()  
{  
  
    $dataProvider=new CActiveDataProvider('Customer', array(  
        'pagination'=>array(  
            'pageSize'=>10,  
            'pageVar'=>'page',  
        ),  
                'sort'=>array(  
                    'defaultOrder'=>'Lastname',  
                    ),  
                ));  
    $this->render('index',array(  
        'dataProvider'=>$dataProvider,  
        ));  
}  
 
public function actionIndex()
{
 
$dataProvider=new CActiveDataProvider('Customer', array(
'pagination'=>array(
'pageSize'=>10,
'pageVar'=>'page',
),
'sort'=>array(
'defaultOrder'=>'Lastname',
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
 
 
 
显示结果如下:
 
 
Yii Framework Development Tutorial Zii Component-ListView Example_PHP Tutorial

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477838.htmlTechArticleCListView可以用来显示列表,CListView支持使用自定义的View模板显示列表的的记录,因此可以非常灵活的显示数据的表,这点有点像Android的Li...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template