codeigniter 路由(正则表达式)
我正在尝试按如下方式路由网址:
domain.com/param/some_controller/method/
映射到
some_controller::method($param)
我不熟悉正则表达式,我相当确定这是必要的,所以如果有人可以帮助我开始,我将非常感激?或者给我指出一个好的教程或示例?
I am trying to route a url as follows:
domain.com/param/some_controller/method/
mapped to
some_controller::method($param)
I am not skilled with regular expressions, which i'm fairly certain are necessary, so I would really appreciate it if someone could help get me started? Or point me to a good tutorial or example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的参数是数字,请使用
(:num)
代替。在你的控制器中,
有一个 RL 示例:
你的视图将类似于
view.php
if your param is a number use
(:num)
instead.in your controller
an RL example:
your view will look like
view.php
这有点混乱,因为目前还没有办法在不造成混乱的情况下通过路由来做到这一点。你可以尝试这个:
但这意味着它将适用于任何 url:这会让常规控制器感到困惑。您最好添加一些前缀来标识您应该使用此路由处理的请求:例如
This is a little messy, because there is currently no way to do this with routing without confusing things. You can try this:
BUT what this says is that it will apply to ANY url: this will confuse regular controllers. You are better served adding some prefix to identify requests you should process with this route: for example
效果相同,但采用 Codeigniter 风格:
Same effect, but Codeigniter-style: