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

Yii2: Pagination and LinkPager - starts at page 0?

我刚刚使用 Pagination class as well as the LinkPager 构建了一个分页系统,但注意到出于某种原因页面编号从 0 开始?

这很烦人,因为分页生成的链接 "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,
    ],
]);

此代码也在class初始化上运行:

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

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

LIMIT 25 OFFSET 25

如果我把它改成:

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

然后它只是追加:

LIMIT 25

有没有办法让它从第 1 页开始?

删除

'page' => $this->page, 

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