URL 段 - 用户个人资料 - Codeigniter
我正在尝试为我的网站创建用户配置文件,其中 URL 类似于
mysite.com/user/ChrisSalij
目前我的控制器看起来像这样:
<?php
class User extends Controller {
function user(){
parent::Controller();
}
function index(){
$data['username'] = $this->uri->segment(2);
if($data['username'] == FALSE) {
/*load default profile page*/
} else {
/*access the database and get info for $data['username']*/
/*Load profile page with said info*/
}//End of Else
}//End of function
}//End of Class
?>
目前,每当我访问时,我都会收到 404 错误;
mysite.com/user/ChrisSalij
我认为这是因为它期望有一个名为 ChrisSalij 的方法。 虽然我确信我也滥用了 $this->uri->segment();
命令,但如有
任何帮助,我们将不胜感激。 谢谢
I'm trying to create user profiles for my site where the URL is something like
mysite.com/user/ChrisSalij
Currently my controller looks like so:
<?php
class User extends Controller {
function user(){
parent::Controller();
}
function index(){
$data['username'] = $this->uri->segment(2);
if($data['username'] == FALSE) {
/*load default profile page*/
} else {
/*access the database and get info for $data['username']*/
/*Load profile page with said info*/
}//End of Else
}//End of function
}//End of Class
?>
At the moment I'm getting a 404 error whenever i go to;
mysite.com/user/ChrisSalij
I think this is because it is expecting there to be a method called ChrisSalij.
Though I'm sure I'm misusing the $this->uri->segment();
command too
Any help would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为控制器正在寻找一个名为 ChrisSalij 的函数。
解决此问题的几种方法:
更改
函数索引(){
$data['用户名'] = $this->uri->segment(2);
并使用
mysite.com/user/index/ChrisSalij 的 URL
并使用类似的内容来
正确映射
的 URL mysite.com/user/ChrisSalij
It's because the controller is looking for a function called ChrisSalij.
A few ways to solve this:
change
function index(){
$data['username'] = $this->uri->segment(2);
to be
and use the URL of mysite.com/user/index/ChrisSalij
and use something along the lines of
to correctly map the URL of
mysite.com/user/ChrisSalij