简体   繁体   English

Codeigniter - 未定义变量:id

[英]Codeigniter - Undefined variable: id

I don't know where's the error but it always shows undefined variable.我不知道错误在哪里,但它总是显示未定义的变量。 Here's my code:这是我的代码:

Model Model

class profile_info extends CI_Model {

    public function get_profile_information($id)
    {
        $query = $this->db->get_where('accountSystem', array('id' => $id));
        return $query->row(); 
    }
}

Controller Controller

class home extends CI_Controller {

    public function display_name()
    {
        $this->load->model('profile_info');
        $data['profile'] = $this->profile_info->get_profile_information($id);
        $this->load->view('account_info_view', $data);
    }
}

View看法

<!DOCTYPE html>
<html>
<head>
    <title>Account Information</title>
</head>
<body>

<h1><?php echo $profile->name; ?></h1>

</body>
</html>

Thank you!谢谢!

In the display_name() function I didn't see any parameter being passed (in this case, it's $id ).display_name() function 我没有看到任何参数被传递(在这种情况下,它是$id )。

So eventually the $id variable $this->profile_info->get_profile_information($id) will appears undefined.所以最终$id变量$this->profile_info->get_profile_information($id)将出现未定义。 Give display_name() function a parameter.display_name() function 一个参数。

Ex: display_name($id) {...} .例如: display_name($id) {...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM