0
我刚刚使用Pagination类以及LinkPager构建了分页系统,但注意到页面计数从0
开始出于某种原因?Yii2:分页和LinkPager - 从第0页开始?
这是相当恼人的分页生成的链接“第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
有没有什么办法让它启动@页面1呢?
从您的分页数组中删除'page'=> $ this-> page,这将使用框架的默认页面选项进行分页。 – 2015-01-21 06:57:19
@NeerajKumar真棒。非常感谢,工作。随意发布作为答案。干杯! – Brett 2015-01-21 07:11:08