dqdjfb2325 2017-10-03 11:24
浏览 28
已采纳

使用user_id在codeigniter中的视图页面上回显用户信息

I'm trying to make a link to a viewpage with using the user_id to display the other user information like for example name and email. This is the link I'm trying to make:

<?php foreach($userdetail_list as $row) { ?>
    <tr>
        <td><a href="<?php echo base_url() . 'User/profiel_user/'.$row['user_id']?>">
    </tr>
<?php } ?>

Now I'm trying to gather the user information that belongs to the user_id that I clicked on. When I click on the link I do see that the link changes to the right user : User/profiel_user/6 But it says 404 Page not found

My User_model file:

<?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();
        }
    }
}
?>

my full User.php controller file:

<?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');
    }
}
?> 

What I have on the view page (profiel_user.php) where the link is linking to:

<?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>

I hope someone can figure out what I'm doing wrong and why I can not use the user_id to echo or display other user_information.

Database: table name: users And user_id is my primary key

  • 写回答

1条回答 默认 最新

  • duangouhui0446 2017-10-03 11:27
    关注

    Your method name is userdetails not profiel_user so change your href

    <td><a href="<?php echo base_url() . 'User/profiel_user/'.$row['user_id']?>">
    

    to

    <td><a href="<?php echo base_url() . 'User/userdetails/'.$row['user_id']?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用