[英]codeigniter : user profile page
Hello i have problem with the user profile page in codeigniter . 您好我在codeigniter中的用户个人资料页面有问题。 So here is my user controller :
所以这是我的用户控制器:
<?php
class User extends CI_Controller {
function users() {
parent::user();
}
function index($id = null) {
if($id == null) {
redirect('/', 'refresh');
}
else {
$data['title'] = 'User Page';
$data['result'] = $this->users_model->get_user_info();
$data['id'] = $id;
$data['main_content'] = "main/profile_view" ;
$this->load->view('home',$data);
}
}
}
?>
And this is the function in the model : 这是模型中的功能:
public function get_user_info(){
$this->db->where('id' , 'id');
$q = $this->db->get('users');
if ($q->num_rows > 0) {
return $q->result();
} else {
return false;
}
}
And this is the routes file : 这是路线文件:
$route['user/(:any)'] = "user/index/$1";
i get this error in localhost/cc/user/1
Fatal error: Call to a member function get_user_info() on null in C:\xampp\htdocs\cc\application\controllers\user.php on line 12
And i want to know how to display the user data in the view 我想知道如何在视图中显示用户数据
in your controller i think this line: 在你的控制器中我想这一行:
$data['result'] = $this->users_model->get_user_info();
should be: 应该:
$data['result'] = $this->users_model->get_user_info($id);
and in your model this: 在你的模型中:
public function get_user_info(){
$this->db->where('id' , 'id');
should be this: 应该这样:
public function get_user_info($id){
$this->db->where('id' , $id);
// ================= next question // =================下一个问题
i tried it , but when i enter a non exist id after user/. 我试过了,但是当我在用户/之后输入一个不存在的id。 , it displays the profile vue
,它显示配置文件vue
yeah i was going to wrap it in an IF but then got lazy -- here's one way check if the result did not come back -- so after you check to see if $id is NULL -- if $data['result'] did not come back from the model then go to a method like showUserNotFound($id). 是的,我打算把它包装在一个IF但是后来变得懒惰 - 这里是一种方法检查结果是否没有回来 - 所以在你检查$ id是否为NULL之后 - 如果$ data ['result']没有从模型回来然后转到像showUserNotFound($ id)这样的方法。
elseif ( ! $data['result'] = $this->users_model->get_user_info($id) ){
$this->showUserNotFound($id); }
else { $data['title'] = 'User Page';
$data['id'] = $id;
$data['main_content'] = "main/profile_view" ;
$this->load->view('home',$data); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.