Hi
I have pagination on page with url:
http://domain.dev/alias-category-4/
Links in the pagination have this structure
http://domain.dev/alias-category-4/?page=3
So as you can see ‘page’ is a query parameter
Is it possible to generate pagination urls like this?
http://domain.dev/alias-category-4/page-3/
My config
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix' => '/',
'rules' => [
'<alias:[a-z0-9-]+>-category-<id:\d+>' => 'category/view',
'<alias:[a-z0-9-]+>-category-<id:\d+>/page-<page:\d+>' => 'category/view',
'<alias:[a-z0-9-]+>-country-<id:\d+>' => 'country/view',
'<alias:[a-z0-9-]+>-country-<id:\d+>/page-<page:\d+>' => 'country/view',
'<alias:[a-z0-9-]+>-type-<id:\d+>' => 'type/view',
'<alias:[a-z0-9-]+>-type-<id:\d+>/page-<page:\d+>' => 'type/view',
'<alias:[a-z0-9-]+>-post-<id:\d+>' => 'post/view',
],
],
Pagination in the model
$answer = [
'items' => false,
'pagination' => false,
];
$query = Post::find()
->with($with)
->where($where);
$countQuery = clone $query;
$pagination = new Pagination(['totalCount' => $countQuery->count(), 'pageSizeParam' => false, 'forcePageParam' => false]);
$pagination
->setPageSize(Yii::$app->params['pagination']['posts']);
$answer['pagination'] = $pagination;
$answer['items'] = $query->offset($answer['pagination']->offset)
->limit($answer['pagination']->limit)
->all();
return $answer;
view file
<?php if($posts['pagination']): ?>
<?= \yii\widgets\LinkPager::widget([
'pagination' => $posts['pagination'],
]); ?>
<?php endif; ?>