CodeIgniter-消息:未定义的变量:数据

时间:2015-11-12 17:20:42

标签: php codeigniter

我正在制作一个向我展示数据库数据的视图。

但结果是

严重性:注意

消息:未定义的变量:数据

文件名:mentee / index.php

UserModel.php

<?php

class UserModel extends CI_Model{

    public function __construct(){
        parent::__construct();
    }


    public function userProfile($nim){
        $this->db->where('userNIM',$nim);
        $query= $this->db->get('msuser');
        return $query->result();
    }

}

MainController.php

public function indexMentee()
    {
        $this->load->model('UserModel');
        $userID=$this->session->userdata("userNIM");
        $data['data'] = $this->UserModel->userProfile($userID);
        $this->load->view('mentee/index', array('data' => $data));

     }

查看

<?php 
die(var_dump($data));
if(is_array($data)){
    foreach ($data as $profile): 

?>
        <div class="header-content">
            <div class="header-content-inner">
                <h1>Learning Center</h1>
                <hr>    
                <h3> Welcome,<?php echo $profile->userName ?></h3>                                
            </div>
        </div>
<?php
    endforeach;
}
?>

请帮助我......非常感谢!

2 个答案:

答案 0 :(得分:2)

而不是传递array('data' => $data));只是将$data传递给视图。

答案 1 :(得分:0)

首次打印会话数据。如果会话数据存在,则将数据传递到查看页面

$data['details'] = $this->UserModel->userProfile($userID);
$this->load->view('mentee/index', $data);

在您的视图页上打印print_r($details);