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']?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度