【问题标题】:change rules in yii URL manager for friendly URLs在 yii URL 管理器中更改友好 URL 的规则
【发布时间】:2014-09-29 00:39:19
【问题描述】:

我有一个需要两个参数的控制器

 public function actionIndex($type = 'recent-jokes',$offset = 0)
 // rest of codes

我希望 URL 是这样的,以便它可以从 URL 中获取参数

something.com/items/type/offset

现在这是我在 main.php 中的配置

 'rules'=>array(
    ''=>'items/index',
    '<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),

你能帮帮我吗:)
非常感谢这个很棒的社区

【问题讨论】:

    标签: url yii url-rewriting yii-url-manager


    【解决方案1】:
     'rules'=>array(
        'items/<type:\w+>/<offset:\w+>' => 'items/index',
        /* other rules */
      ),
    

    你去。

    【讨论】:

    • 还有一个小问题,我如何才能得到 offset 的值?
    • 你可以将值传递给控制器​​中的视图
    猜你喜欢
    • 2016-09-27
    • 2012-12-02
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 2012-07-05
    相关资源
    最近更新 更多