问题
I'm trying to create paging in an application with the following custom rules
'enablePrettyUrl' => true,
'rules' => [
'/<id:\d+>' => 'news/view',
'/<link>' => 'news/view',
'/<technology>/<news>' => 'category/index',
'/<technology>/<tags>/<title>' => 'category/tag',
'<controller:\w+>/<action:\w+>/<id:\d+>' =>'<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',]
So how do I write the rule for paging which creates a url like this
http://localhost/project/frontend/web/site/index?page=2&per-page=3
I've tried this
'<controller:\w+>/<action:\w+>/<page>/<pg:\d+>/<per-page>/<pg2:\d+>' => 'site/index',
but it's diverting to this rule instead
'/<technology>/<news>' => 'category/index',
回答1:
In case someone else encounters a similar problem, I solved this by creating a route for the base url like so:
'site/<title:\w+>'=>'site/index'
then I created a route with the page parameter
'site/<title:\w+>/<page:\d+>'=>'site/index'
Everything worked like charm
来源:https://stackoverflow.com/questions/41335785/yii2-paging-with-custom-url-rules