CodeIgniter路由

发布于 2024-11-27 00:23:11 字数 455 浏览 1 评论 0原文

我需要编写一个 CI 路由,以便加载正确的控制器。我想做的是编写一条排除“features”控制器的路由。这是我的路线(但第一个不起作用)。

$route['(\w{2})/(\w{2})/products/([\w]+!features)'] = "products/products/$3";  // folder/controller/method
$route['(\w{2})/(\w{2})/products/features/([\w]+)'] = "products/features/$3";  // folder/controller/method

我想要发生的是顶行应该加载任何不是功能控制器的控制器。但我发现两条线之间存在冲突。我尝试将“!features”放置在行中的几个不同位置,带引号和不带引号,但我仍然可以加载功能控制器或加载产品控制器中的其他方法之一。但不是两者兼而有之。有人可以帮忙吗?谢谢。

I need to write a CI route so that it loads the right controller. What I want to do is write a route that excludes the "features" controller. Here are my routes (but the first one doesn't work).

$route['(\w{2})/(\w{2})/products/([\w]+!features)'] = "products/products/$3";  // folder/controller/method
$route['(\w{2})/(\w{2})/products/features/([\w]+)'] = "products/features/$3";  // folder/controller/method

What I want to have happen is the top line should load any controller that is not the features controller. But I am getting conflicts between the two lines. I've tried placing the "!features" in a couple of different places in the line, with and without quotes and I'm still getting either the features controller to load or one of the other methods in the products controller to load. But not both. Can someone help out here? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2024-12-04 00:23:11

尝试将第一行更改为:

$route['(\w{2})/(\w{2})/products/(?!features$)(\w+)'] = "products/products/$3";
  • (?!foo) 是负向前瞻,如果后面的任何内容与 foo 匹配,则失败。
  • $ 表示字符串结尾,是为了确保 features 不是较长单词的一部分。

Try changing the first line to:

$route['(\w{2})/(\w{2})/products/(?!features$)(\w+)'] = "products/products/$3";
  • (?!foo) is a negative lookahead, if fails if whatever is following it matches foo.
  • $ means end of string, and is there to make sure that features is not part of a longer word.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文