Codeigniter _remap函数
请帮助我想在我的 CodeIgniter 网站中使用第一个 URI 段。
就像当我打开这些网址时,他们会打开我的个人资料: http://www.facebook.com/buddyforever 或者 http://www.myspace.com/zarpio
如何使用 CodeIgniter 执行此操作?我检查了 _remap
函数,但先来的控制器如何隐藏控制器?
Please help I want to use first URI segment into my CodeIgniter website.
Like when I open these url they opens my profile:
http://www.facebook.com/buddyforever
or
http://www.myspace.com/zarpio
How can I do this with CodeIgniter? I checked _remap
function but first coming controller how to hide controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 codeigniter 的 URL 路由来完成此操作...
如果您希望 URL 为
http://www.mydomain.com/zarpio
并且希望它引用your_controller< /code>,然后执行以下操作。
/config/routes.php
您可以像这样在控制器中访问它...
但是我不建议这种配置 URL 的方式。更好的方法是...
这样,您只需将控制器名称
your_controller
重命名为users
即可。如果您想访问用户的个人资料,您可以这样做......
考虑路由的顺序。由于您在路由中写入了
users/(.*)
,因此它将匹配users/zarpio
以及users/profile/zarpio
,并且将它们都路由到your_controller/$1
,在配置文件的情况下会给您一个404 page not found
错误。这就是为什么您需要在路由配置中的users/(.*)
之前编写users/profile/(.*)
。更多信息请参见 codeigniter URI 类文档
You can do this using the URL routing of codeigniter...
If you want your URL to be
http://www.mydomain.com/zarpio
and you want it to refer toyour_controller
, then do the following./config/routes.php
You can access it in your controller like this...
However I do not suggest this way of configuring URLs. A better way would be...
This way, you're just renaming your controller name
your_controller
tousers
.If you want to access profile of a user, you can do it like this...
Consider the order of routing. Since you wrote
users/(.*)
in your route, it will matchusers/zarpio
as well asusers/profile/zarpio
, and route both of them toyour_controller/$1
, which in the case of profile will give you a404 page not found
error. That is why you need to writeusers/profile/(.*)
beforeusers/(.*)
in your routing configuration.More information in codeigniter URI class documentation