I need you help. I trying to find right solution for my task.
Imagen, I have a books
id | name
--------
1 | book1
2 | book2
and books has chapters
id | name | book_id
-------------------
1 | chapter1 | 1
2 | chapter2 | 1
There is page for book and another page for chapters with pagination limit 1 record of chapter on page.
So, what I'm trying to do: on the book page I have chapters links and I need to generate links to chapter page with page pagination attribute. Question is how to detect page number of needed chapter?
For some reason I'm using ArrayDataProvider
instead of ActiveDataProvider
in controller method for chapters list. Your answers can be based on ActiveDataProvider
. Index or PK of chapter cannot be used for page number in my case.
//Controller action (chapters page with pagination)
public function actionRead($id)
{
$this->layout = 'main-pure-header';
$query = Chapter::find()->where(['prose_id' => $id])
->orderBy('id asc');
$chapterPages = ChapterHelper::explodeChapter($query->all(), self::PER_PAGE);
$chapterProvider = new ArrayDataProvider([
'allModels' => $chapterPages,
'pagination' => [
'pageSize' => 1,
'pageSizeParam' => false
]
]);
return $this->render('/prose/large-all', [
'chapterProvider' => $chapterProvider
]);
}
//VIEW (chapters page with pagination)
<?= LinkPager::widget([
'pagination' => $chapterProvider->pagination,
'maxButtonCount' => 0,
'prevPageLabel' => 'Next page',
'nextPageLabel' => 'Prev page'
]); ?>
Thanks in advance!
Updated #1
Here is chapters list on the book page
<?php foreach ($prose->chapters as $chapter) { ?>
<li>
<div class="container">
<?= Html::a($chapter->name, ['large/read', 'id' => $chapter->prose->id, 'page' => '???']) ?>
</div>
</li>
<?php } ?>