Case Analysis of Yii Framework Paging Technology
- 2021-12-19 06:15:01
- OfStack
This paper describes the paging technology of Yii framework with examples. Share it for your reference, as follows:
Directly on the code:
1. Write the controller layer first
Refer to the pagination class first
use yii\data\Pagination;
Write Your Own Way:
function actionFenye(){
$data = Field::find(); //Field For model Layer , At the beginning of the controller use It's over field This model, You can write it directly here Field, You can start with both case and case , In order to standardize , I wrote it in capitals
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '2']); // Instantiate the paging class , With parameters ( Total number of articles , Number of items displayed per page )
$model = $data->offset($pages->offset)->limit($pages->limit)->all();
return $this->renderPartial('fenye',[
'model' => $model,
'pages' => $pages,
]);
}
2. The model layer is directly used../yii/frontend/web/index. php? r=gii generated model (detailed link)
3. Finally, the display page
<?php
use yii\widgets\LinkPager;
?>
<?php foreach($model as $key=>$val){ ?>
<?= $val->Id; ?> // Equivalent to <?php echo $val['Id']; ?>
<?= $val->Field; ?> // Equivalent to <?php echo $val['Field']; ?>
<?php } ?>
<?=
LinkPager::widget([
'pagination' => $pages,
]);
?>
You can try 1 by yourself
For more readers interested in Yii related content, please check the topics on this site: "Introduction to Yii Framework and Summary of Common Skills", "Summary of Excellent Development Framework of php", "Introduction to smarty Template", "Introduction to php Object-Oriented Programming", "Summary of Usage of php String (string)", "Introduction to php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"
I hope this article is helpful to the PHP programming based on Yii framework.