PHP Development Framework Yii Framework Tutorial (a) Zii component-listview sample

Source: Internet
Author: User
Tags php and yii

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,     
        ));     
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.