public function setPageSize($value, $validatePageSize = false) { if ($value === null) { $this->_pageSize = null; } else { $value = (int) $value; if ($validatePageSize && isset($this->pageSizeLimit[0], $this->pageSizeLimit[1]) && count($this->pageSizeLimit) === 2) { if ($value < $this->pageSizeLimit[0]) { $value = $this->pageSizeLimit[0]; } elseif ($value > $this->pageSizeLimit[1]) { $value = $this->pageSizeLimit[1]; } } $this->_pageSize = $value; } }
public static function getPagedRows($query, $tablename, $params, $config = []) { $countQuery = clone $query; if (isset($params['SqlAttackSearch']) || isset($params['SqlLogSearch']) || isset($params['ErrorLogSearch'])) { //$rownums['nums'] = $countQuery->count(); //在条件查询时不处理分页,给一个大概数 $rownums['nums'] = 10000000; } else { $rownums = Yii::$app->db->createCommand("select TABLE_ROWS nums from information_schema.TABLES where TABLE_SCHEMA='Tuandai_Log' and TABLE_NAME='" . $tablename . "'")->queryOne(); } $pages = new Pagination(['totalCount' => $rownums['nums']]); if (isset($config['pageSize'])) { $pages->setPageSize($config['pageSize'], true); } $rows = $query->offset($pages->offset)->limit($pages->limit); if (isset($config['orderBy'])) { $rows = $rows->orderBy($config['orderBy']); } $rows = $rows->all(); $rowsLable = 'datas'; $pagesLable = 'pager'; if (isset($config['rows'])) { $rowsLable = $config['rows']; } if (isset($config['pages'])) { $pagesLable = $config['pages']; } $ret = []; $ret[$rowsLable] = $rows; $ret[$pagesLable] = $pages; return $ret; }