【问题标题】:Yii2 Paging with custom url rulesYii2 带有自定义 url 规则的分页
【发布时间】:2016-12-27 04:35:05
【问题描述】:

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

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

那么我该如何编写创建这样一个 url 的分页规则

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

我试过了

'&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;page&gt;/&lt;pg:\d+&gt;/&lt;per-page&gt;/&lt;pg2:\d+&gt;' =&gt; 'site/index',

但它正在转向这条规则

'/&lt;technology&gt;/&lt;news&gt;' =&gt; 'category/index',

【问题讨论】:

    标签: yii2


    【解决方案1】:

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

    'site/&lt;title:\w+&gt;'=&gt;'site/index'

    然后我用页面参数创建了一个路由

    'site/&lt;title:\w+&gt;/&lt;page:\d+&gt;'=&gt;'site/index'

    一切都像魅力一样运作

    【讨论】:

    • 请注意,&lt;page:\d&gt; 的规则似乎必须在您的其他规则之前
    猜你喜欢
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 2014-05-30
    • 2015-12-26
    相关资源
    最近更新 更多