路由控制器的所有操作(除了 codeigniter 中的操作)

发布于 2024-12-13 20:11:07 字数 595 浏览 1 评论 0原文

我正在 CodeIgniter 中做一个项目,我想将特定控制器的所有 url 路由到除一个之外的特定操作。例如, 我希望该 url

myurl/mycontroller/myaction

由操作 myaction 处理,但任何其他 url 都希望

myurl/mycontroller/myaction1
myurl/mycontroller/myaction2
myurl/mycontroller/myaction3

由特定控制器的操作 abc 处理。我在互联网上进行了搜索,得到的是如何通过某个控制器处理除某些之外的所有网址。这样做的方法是

$route['^(?!admin|user|setup|pages).*'] = "user/view/$0";

这里所有的url都将由user/view处理,除了那些url的第二部分是adminuser的url >、设置页面

I am doing a project in CodeIgniter and I want to route all the urls of a particular controller to a specific action except one. For e.g.,
I want the url

myurl/mycontroller/myaction

to be handled by the action myaction but any other urls like

myurl/mycontroller/myaction1
myurl/mycontroller/myaction2
myurl/mycontroller/myaction3

to be handled by action abc of a particular controller. I had searched across the internet and what I get is how to handle all urls by a certain controller except some. The way to do it is

$route['^(?!admin|user|setup|pages).*'] = "user/view/$0";

Here all urls will be handled by user/view except those whose 2'nd part of the url is admin, user, setup or pages.

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

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

发布评论

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

评论(2

烟酒忠诚 2024-12-20 20:11:07

我认为路由是按顺序应用的,那么在其他路由之前先添加“myaction”路由怎么样?

$route['myurl/mycontroller/myaction'] = "myurl/mycontroller/myaction";
$route['myurl/mycontroller/abc'] = "myurl/mycontroller/$1";

I think routes are applied in order, so how about adding a route for the "myaction" first before the other ones?

$route['myurl/mycontroller/myaction'] = "myurl/mycontroller/myaction";
$route['myurl/mycontroller/abc'] = "myurl/mycontroller/$1";
追风人 2024-12-20 20:11:07

我相信这是正确的语法

$route['myurl/mycontroler/myaction(:any)'] = "myurl/controller_a/action";

您可以在此处验证

它编辑

我阅读了您的评论并且我做出了调整。试一试,看看是否合适。

编辑 2

好吧,既然您只希望确切的单词 myaction 不受损害,那么可以在单词后使用 (:any) 或 (\d+) ,这样当数字附加到 myaction 单词时就会发生重新路由。我还没有实际测试过。

I believe this is the correct syntax

$route['myurl/mycontroler/myaction(:any)'] = "myurl/controller_a/action";

You can verify it here

EDIT

I read your comment and I made an adjustment. Give it a go and see if it fits.

EDIT 2

Well since you just want the exact word myaction unharmed then either use (:any) or (\d+) after the word so the rerouteing happens when a number is attached to the myaction word. I haven't actually tested it yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文