duanlujiaji10335 2015-03-26 07:47
浏览 48
已采纳

使用Yii2进行网址管理

I have a problem with Yii2's urlManager. I have an action with url category/index, where I pass ?par=test as param.

I want to create an alias for my url so that when par is not specified the url will be /test, but when it is specified the url should be /test/some-value. Here is my config for now:

       'rules' => [
            [
                'pattern' => 'test',
                'route'   => 'category/index',
            ],
            '<subcats: (val|some-value)>' => 'test/<subcats>',
  • 写回答

1条回答 默认 最新

  • doushi9376 2015-03-26 10:28
    关注

    If you need url like category/index/test/some-value. Use that

    'category/index/test/<val:\w+>' => 'category/index'
    

    In controller in method index use that:

    public function actionIndex($val){
    

    Yii2 automatically provide parameter $val in action.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部