在codeigniter中的视图中的未定义变量

时间:2016-07-06 09:11:10

标签: php codeigniter

我的控制器在这里

class Admin extends CI_Controller { 


function __construct(){
    parent::__construct();
}
public function index($msg = NULL) {
     $data['msg'] = $msg;

    $this->load->view('pages/sign-in');

}
 public function process(){
    // Load the model
    $this->load->model('admin/Admin_model');
    // Validate the user can login
    $result = $this->Admin_model->validate();
    // Now we verify the result
    if(! $result){
        // If user did not validate, then show them login page again
        $msg = '<font color=red>Invalid username and/or password.</font><br />';
        $this->index($msg);
    }else{
        // If user did validate, 
        // Send them to members area
        redirect(base_url().'index.php/home');
    }        
} 

这是我正在使用的视图文件:

if(! is_null($msg)) echo $msg;

显示

  

未定义的变量$ msg

1 个答案:

答案 0 :(得分:2)

您没有将数据数组传递到视图中。试试这个:

$this->load->view('pages/sign-in', $data);