如何在 codeigniter 中制作永久链接......社会案例
我想使用 codeigniter 建立一个网站。该网站看起来就像我学校的社交聚合器。为了建立我的网站,我计划:
- 制作一个类“页面”。 “pages”类有一个常用的功能login,
注册,注销......等 - 创建一个“用户”类,“用户”类具有与以下相关的功能 用户需求,例如:编辑个人资料、添加社交 api、view_profile 等。
我知道如果我们想查看个人资料,我们应该传递一个网址,例如:
www.Mysite.com/user/view_profile/ <user name>
我不知道如何制作直接用户页面(例如永久链接) )。我希望我的用户只需输入即可访问他的页面:
www.Mysite.com/ <user name>
我已阅读代码点火器中的 user_guide 但我仍然不明白 url 类别。有谁可以解释一下如何制作吗?
i want to build a website using codeigniter. The website is look like a social agregator for my school. to build my website i plan :
- making a class "pages". The class "pages" has a common function login,
register , logout.. etc. - making a "user" class the class "user" has a function related to
user needs like: edit profile, add social api, view_profile etc.
i know if we want to see a profile we should pass an url like :
www.Mysite.com/user/view_profile/ <user name>
I dont know how to make a direct user pages (like permalink). i want my user can access his pages just only to type:
www.Mysite.com/ <user name>
i have read the user_guide in code igniter but i still dont understand what the url clas. is there any body can explain me how to make it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将在
application/config/routes.php
中设置一条路由,将任何以用户名作为第一段的 URL 重新映射到为您的个人资料视图提供服务的控制器方法。例如,在您的routes.php中放置以下代码:
$route[':any'] = "user/view_profile/:any";
:any
键将为作为变量传递给函数。请记住,默认情况下,该路由中的任何内容(任何内容)都将被路由到该控制器的方法,因此让您的永久链接结构如下所示可能是一个好主意:yoursite.com/u/
yoursite.com/u/< username>
,在这种情况下你不需要路由;你可以像这样传递 uri 段:I would set up a route in
application/config/routes.php
that remaps any URL with a username as the first segment to the controller's method serving your profile view.For instance, in your routes.php place this code:
$route[':any'] = "user/view_profile/:any";
The
:any
key will be passed as a variable to the function. Keep in mind that, by default, anything in that route (anything) will be routed to that controller's method, so it might be a good idea to have your permalink structure look like this:yoursite.com/u/<username>
, in which case you don't need a route; you can just pass the uri segment like this: