我尝试使用user_id显示其他用户信息(例如姓名和电子邮件),从而建立到视图页面的链接。这是我试图制作的链接:
<?php foreach($userdetail_list as $row) { ?>
<tr>
<td><a href="<?php echo base_url() . 'User/profiel_user/'.$row['user_id']?>">
</tr>
<?php } ?>
现在我正在尝试收集属于我点击的user_id的用户信息。 当我点击链接时,我确实看到该链接更改为正确的用户:User / profiel_user / 6 但它说404找不到页面
我的User_model文件:
<?php
class User_model extends CI_Model {
public function getUserInfoByEmail($email) {
$q = $this->db->get_where('users', array('email' => $email), 1);
if($this->db->affected_rows() > 0){
$row = $q->row();
return $row;
}else{
error_log('no user found getUserInfo('.$email.')');
return false;
}
}
public function getUserInfo($user_id) {
$q = $this->db->get_where('users', array('user_id' => $user_id), 1);
if($this->db->affected_rows() > 0){
$row = $q->row();
return $row;
}else{
error_log('no user found getUserInfo('.$user_id.')');
return false;
}
}
public function getdata() {
$this->db->where('user_id', $id);
$this->db->from('users');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
}
}
?>
我的完整User.php控制器文件:
<?php
class User extends CI_Controller {
public function index() {
$this->load->view('profile', $data);
}
public function __construct() {
parent::__construct();
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
}
public function userdetails($user_id) {
//load the User_model
$this->load->model('User_model');
//call function getdata in de Product_model
$data['userdata_list'] = $this->User_model->getdata();
//get product details
$data['user'] = $this->User_model->get_user_info($user_id);
//laad view
$data['main_content'] = 'profiel_user';
$this->load->view('profiel_user', $data);
}
public function profile() {
$this->load->model('User_model');
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
$this->load->view('profile');
}
}
?>
链接链接到的视图页面(profiel_user.php)上有什么:
<?php include_once ('templates/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<center>Gebruikersprofiel</center>
</div>
</div>
</div>
<?php foreach($userdata_list as $row) { ?>
<tr>
<td><?php echo $row['email']; ?></td>
</tr>
<?php } ?>
<?php include_once ('templates/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<center>Gebruikersprofiel</center>
</div>
</div>
</div>
我希望有人能弄清楚我做错了什么以及为什么我不能使用user_id来回显或显示其他user_information。
数据库: 表名:用户 而user_id是我的主键
答案 0 :(得分:1)
您的方法名称为userdetails
而不是profiel_user
,因此请更改您的广告
<td><a href="<?php echo base_url() . 'User/profiel_user/'.$row['user_id']?>">
到
<td><a href="<?php echo base_url() . 'User/userdetails/'.$row['user_id']?>">