Yii Framework Development Tutorial Zii Component-listview Sample _php Tutorial

Source: Internet
Author: User
Tags yii
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. [PHP] 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 ',),);?> 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 displays templates, supported parameters are {summary}, { Sorter}, {items} and {pager}, respectively, correspond to the summary, sort, list item, and pagination control of the ListView. The parameter Itemview indicates the view display for each list item. This example uses site/_view.php, which is 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);?>
Then modify the Indexaction method of the Sitecontroller: [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,)); The 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:

http://www.bkjia.com/PHPjc/477838.html www.bkjia.com true http://www.bkjia.com/PHPjc/477838.html techarticle 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 Li ...

  • 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.