Yii2:分页和LinkPager - 从第0页开始?

时间:2015-01-21 06:12:48

标签: php yii yii2

我刚刚使用Pagination类和LinkPager构建了一个分页系统但注意到页面编号由于某种原因从0开始?

由于分页产生了链接,因此它很烦人,并且#34; Page 1"第1页,实际上是第2页。

这是我的通用代码:

$sql = $this->db->createCommand("SELECT COUNT(*) FROM some_table WHERE some_id=:some_id");
$sql->bindValue(':some_id', $this->some_id);
$count = $sql->queryScalar();

$dataProvider = new SqlDataProvider([
    'sql' => 'SELECT t.*, a.image_path, a.upload_date FROM some_table AS t LEFT JOIN other_table AS a ON t.user_id=a.user_id WHERE t.some_id=:some_id',
    'params' => [':some_id' => $this->some_id],
    'totalCount' => $count,
    'sort' => [
        //.............
    ],
    'pagination' => [
        'pageSize' => $this->per_page,
        'page' => $this->page,
        'pageSizeLimit' => [5,100],
        'pageSizeParam' => 'per_page',
        'totalCount' => $count,
    ],
]);

此代码也在类初始化

上运行
$this->page = ($this->page) ? $this->page : 1;

使用上面的代码将以下内容附加到查询中:

LIMIT 25 OFFSET 25

如果我将其更改为:

$this->page = ($this->page) ? $this->page : 0;

然后它只是追加:

LIMIT 25

有没有办法让它从@ page 1开始?

1 个答案:

答案 0 :(得分:2)

删除

'page' => $this->page, 

从您的分页数组中,这将使用框架的默认页面选项进行分页。