Yii2 Paging with custom url rules

醉酒当歌 提交于 2019-12-11 04:50:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!