本文整理汇总了PHP中Paginate::show方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginate::show方法的具体用法?PHP Paginate::show怎么用?PHP Paginate::show使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paginate
的用法示例。
在下文中一共展示了Paginate::show方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: page
/**
* 数据库分页
* @example DB::w()->from(table)->page(['url'=>url,'page'=>10,'class'=>'pagination','count'=>'count(*) num']);
* @param array $condition
* @return 数组 ['data','pages']
*/
function page($condition = [])
{
$url = $condition['url'];
$count = $condition['count'] ?: "count(*) num";
$class = $condition['class'] ?: "pagination";
$per_page = $condition['per_page'];
if (!$per_page) {
$per_page = $condition['page'] ?: 10;
}
unset($condition['url'], $condition['per_page'], $condition['page'], $condition['class']);
if ($condition) {
foreach ($condition as $conditionkey => $conditionValue) {
if (strpos($conditionkey, 'where') !== false) {
$this->{$conditionkey}($conditionValue[0], $conditionValue[1]);
} else {
$this->{$conditionkey}($conditionValue);
}
}
}
$this->count($count);
$this->_query(true);
$query = $this->query;
$row = $query->fetch(PDO::FETCH_OBJ);
$paginate = new Paginate($row->num, $per_page);
$paginate->url = $url;
$limit = $paginate->limit;
$offset = $paginate->offset;
//显示分页条,直接输出 $paginate
$pages = $paginate->show($class);
if ($condition) {
foreach ($condition as $conditionkey => $conditionValue) {
if (strpos($conditionkey, 'where') !== false) {
$this->{$conditionkey}($conditionValue[0], $conditionValue[1]);
} else {
$this->{$conditionkey}($conditionValue);
}
}
}
$this->limit($limit);
$this->offset($offset);
$this->_query(true);
$posts = $this->query->fetchAll();
unset($this->ar, $this->where);
return (object) ['data' => $posts, 'pager' => $pages, 'count' => $row->num];
}