Yii2使用自定义网址规则进行分页

时间:2016-12-26 20:04:03

标签: yii2

我正在尝试使用以下自定义规则在应用程序中创建分页

'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>',]

那么我如何编写分页规则来创建像这样的网址

http://localhost/project/frontend/web/site/index?page=2&per-page=3

我试过这个

'<controller:\w+>/<action:\w+>/<page>/<pg:\d+>/<per-page>/<pg2:\d+>' => 'site/index',

但它转而使用此规则

'/<technology>/<news>' => 'category/index',

1 个答案:

答案 0 :(得分:2)

如果其他人遇到类似的问题,我通过为基本网址创建路由来解决这个问题:

'site/<title:\w+>'=>'site/index'

然后我用页面参数

创建了一个路径

'site/<title:\w+>/<page:\d+>'=>'site/index'

一切都像魅力一样

相关问题