【发布时间】:2017-10-03 11:24:07
【问题描述】:
我正在尝试使用 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 Page not found
我的 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 是我的主键
【问题讨论】:
-
我注意到您正在使用 include_once 在视图页面上加载您的视图 codeigniter 有更好的方法codeigniter.com/user_guide/general/…
-
感谢您的提示
标签: php codeigniter codeigniter-3