路由控制器的所有操作(除了 codeigniter 中的操作)
我正在 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的第二部分是admin
,user
的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为路由是按顺序应用的,那么在其他路由之前先添加“myaction”路由怎么样?
I think routes are applied in order, so how about adding a route for the "myaction" first before the other ones?
我相信这是正确的语法
您可以在此处验证
它编辑
我阅读了您的评论并且我做出了调整。试一试,看看是否合适。
编辑 2
好吧,既然您只希望确切的单词 myaction 不受损害,那么可以在单词后使用 (:any) 或 (\d+) ,这样当数字附加到 myaction 单词时就会发生重新路由。我还没有实际测试过。
I believe this is the correct syntax
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.