CodeIgniter URL 帮助
我计划在 CodeIgniter 中重新创建我的歌词网站。 目前,我的设置方式是这样的:example.com/artistname
和 example.com/anotherartist
我还有 example.com/contact
和 example.com/request< /code> 等等。
我可以将其设置为 example.com/artist/artistname
,但我真的希望保持简单,以便用户记住网址。
谁能帮我解决这个问题吗?
谢谢, 麦克尔
I'm planning on re-creating my lyrics website in CodeIgniter.
At the moment, the way I have it set-up is like this:example.com/artistname
and example.com/anotherartist
I also have example.com/contact
and example.com/request
etc..
I can get it to be example.com/artist/artistname
, but I'd really like to keep it simple for the user to memorize the urls.
Can anyone help me out with this?
Thanks,
Maikel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
application/config/routes.php
中尝试:In
application/config/routes.php
try:通过此处的 CodeIgniter 用户指南: http://codeigniter.com/user_guide/general/routing.html
您可以将任何内容 (
:any
) 重新映射到您的artist
控制器。从那里,您可以将contact
、request
等重新映射到各自的控制器/函数,或者您可以使用构造函数来检查这些并调用正确的函数。示例:使用 URI 路由:
使用构造函数:
但是,此方法可能会导致无限循环。我不建议这样做,除非您的
contact
和request
功能位于同一个控制器中。然后您可以使用$this->contact()
或$this->request()
来调用它们,而不是重定向。Via the CodeIgniter User Guide here: http://codeigniter.com/user_guide/general/routing.html
You can remap anything (
:any
) to yourartist
controller. From there, you can remapcontact
,request
, etc. to their respective controllers/functions or you can use your Constructor to check for those and call the correct function. Examples:Using URI Routing:
Using your Constructor:
This method, however, could result in an infinite loop. I would not suggest it, unless your
contact
andrequest
functions were in the same controller. Then you could just call them with$this->contact()
or$this->request()
instead of the redirect.