ctms/common/components/Attachment.php
2025-04-10 23:19:13 +08:00

45 lines
1.3 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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();
}
}