如何将变量从控制器传递到Codeigniter中的视图?

时间:2015-03-29 10:02:29

标签: php codeigniter

控制器:

$data = array(
    'error_message' => 'Invalid Username or Password'
);
$this->load->view('/login/index', $data);

查看页面:

<?php echo $error_message; ?>

1 个答案:

答案 0 :(得分:0)

我猜您已将view路径设置错误,因此变量未到达view
这是应该的,


控制器:(applications / controllers / filename.php)

$data = array(
    'error_message' => 'Invalid Username or Password'
);

$this->load->view('login/index', $data);   # removed slash here


查看:(applications / views / login / index.php)

<?php echo $error_message; ?>