dongxuanyi3406 2014-08-27 06:03
浏览 81
已采纳

yii2 URL管理两个命名的子模式

I have module structure in my Yii 2.0 application, so I need to call things like

"module/controller/action"

But 90% of modules and controllers have the same names, for example it looks like

"news/news/index"
"support/support/index",
"profile/profile/update"

It looks not good, I'd like to see just "profile/update"... Then I create the following rule in UrlManager:

"<controller:\w+>/<action:\w+>" => "<controller>/<controller>/<action>"

This gets me the error: "preg_match(): Compilation failed: two named subpatterns have the same name at offset 35"

How to solve this problem instead of creating different rules for each module, I don't want my config file has several rules for tens modules.

  • 写回答

2条回答 默认 最新

  • douzhan8395 2014-08-29 07:42
    关注

    I found better solution. PCRE supports modifier "?J" that allows duplicate names for subpatterns. All we need is to add this modifier to our pattern that Yii will use for parsing url. Unfortunately we have to add it manually, in yii/web/UrlRule change line:

    $this->_routeRule = '#^' . strtr($this->route, $tr2) . '$#u';
    

    to:

    $this->_routeRule = '#^(?J)' . strtr($this->route, $tr2) . '$#u';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?