Initial commit,修正
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-21 04:18:24
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2019-10-07 17:16:03
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace common\components;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
class Attachment extends ActiveForm
|
||||
{
|
||||
|
||||
/*处理分页*/
|
||||
private $pagination;
|
||||
/**
|
||||
* 获取$pagination,提供给外部代码调用
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPagination()
|
||||
{
|
||||
return $this->pagination;
|
||||
}
|
||||
public function getData($model,$where,$orderby)
|
||||
{
|
||||
// 预查询,此时还没有执行。where()条件查询、orderBy()排序等都应该放在这里
|
||||
$query = $model->find()->where($where)->orderBy($orderby);
|
||||
// 获取能够查询到的数据条目数量(这就是条件查询等语句要放在上一行代码的原因),但是还没有执行查询
|
||||
$count = $query->count();
|
||||
// 构造分页对象
|
||||
$this->pagination = new Pagination(['totalCount'=>$count,'defaultPageSize' => 12]);
|
||||
// 使用分页对象填充limit语句,并获得数据(此时才真正执行数据库查询)
|
||||
return $query->offset($this->pagination->offset)
|
||||
->limit($this->pagination->limit)
|
||||
->asArray()
|
||||
->all();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user