2015-01-21 54 views
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呢?

+3

從您的分頁數組中刪除'page'=> $ this-> page,這將使用框架的默認頁面選項進行分頁。 – 2015-01-21 06:57:19

+0

@NeerajKumar真棒。非常感謝,工作。隨意發佈作爲答案。乾杯! – Brett 2015-01-21 07:11:08

回答

2

從您的分頁數組中刪除

'page' => $this->page, 

這將使用框架的分頁默認頁面選項。