The examples in this article describe the Yii list definition and the use of paging methods. Share to everyone for your reference, specific as follows:
method One: controller definition
function Actionindex () {
$criteria = new Cdbcriteria ();
$count =article::model ()->count ($criteria);
$pages =new cpagination ($count);
Back to the previous page
$pages->pagesize=10;
$pages->applylimit ($criteria);
$models = Post::model ()->findall ($criteria);
$this->render (' index ', array (
' models ' => $models,
' pages ' => $pages
)
}
View definition:
<?php foreach ($models as $model):?>
//display a model
<?php Endforeach;?>
//Display paging
<?php $ This->widget (' Clinkpager ', Array (
' pages ' => $pages,
))?>
method Two: controller definition:
Public Function Actionindex ()
{
$dataProvider =new cactivedataprovider (' News ', Array (
' criteria ' => Array (
' condition ' => ' status=1 ', ' Order
' => ' create_time DESC ', ' with
' =>array (' author '),
),
' pagination ' =>array (
' pageSize ' =>20,
))
;
$this->render (' index ', array (
' Dataprovider ' => $dataProvider,
));
}
View File:
<?php $this->widget (' Zii.widgets.CListView ', Array (
' Dataprovider ' => $dataProvider,
' Itemview ') => ' _view ',
));?>
method Three: view file
<?php $this->widget (' Zii.widgets.grid.CGridView ', array (' ID ' => ' news-grid ', ' Dataprovider ' => $model- >search (), ' Filter ' => $model, ' template ' => ' {items}{summary}{pager} ', <span style= ' White-space:pre ' > &
Lt;/span> ' Pager ' =>array (' class ' => ' Clinkpager ', ' Header ' => ' page: ', ' Prevpagelabel ' => ' previous page '), ' Nextpagelabel ' => ' next page ',), <span style= "White-space:pre" > </span> ' summarytext ' => ' pages: {page S}/{page} page ', <span style= ' white-space:pre ' > </span> ' Columns ' =>array (' id ', array (' name ' => ' title ') , ' Htmloptions ' =>array (' width ' => ' 20% '), ' value ' => ' mb_substr ' ($data->title,0,10, "Utf-8") , Array (' name ' => ' content ', ' htmloptions ' =>array (' width ' => ' 20% '), ' value ' => ' Mb_substr (strip_t AGS ($data->content), 0,10, "utf-8") ', ', Array (' Name ' => ' type ', ' Value ' => ' News::model ()->getnews Type ($data->type) ',), ' user ', Array (' name ' => ' status ', ' Value ' => ' News::model ()->getnewsstatus ($data->status) ',
), array (' class ' => ' Cbuttoncolumn ',),));
Data Model classes:
Public Function Search ()
{
$criteria =new Cdbcriteria;
$criteria->compare (' id ', $this->id);
$criteria->compare (' title ', $this->title,true);
$criteria->compare (' content ', $this->content,true);
$criteria->compare (' type ', $this->type);
$criteria->compare (' user ', $this->user,true);
$criteria->compare (' status ', $this->status);
$criteria->compare (' Create_data ', $this->create_data,true);
return new Cactivedataprovider ($this, Array (
' criteria ' => $criteria,
' pagination ' =>array (
' PageSize ' =>50,
),)
}
For more information on YII-related content, readers who are interested in this site can view the topics: Introduction to YII Framework and summary of common skills, "Summary of PHP Excellent development framework", "Smarty Template Introductory Course", "Introduction to PHP object-oriented programming", "PHP string" Summary of Usage , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the YII framework.