2012-02-13 81 views
-1

這裏的PHP的致命錯誤,這是我的代碼:得到笨控制器

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Login extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->database(); /* This function it's used to connect to database */ 
     $this->load->model('User','user'); /* This call the model to retrieve data from db */ 
    } 

    public function index() 
    { 
     if(!file_exists('application/views/_login.php')) 
     { 
      show_404(); 
     } 

     $this->load->library('form_validation'); 

     $this->form_validation->set_error_delimiters('<h4 style="text-align:center;">','</h4>'); 

     $this->form_validation->set_rules('username','username','trim|required|xss_clean'); 
     $this->form_validation->set_rules('password','password','trim|required|xss_clean|callback_pass_check'); 

     if($this->form_validation->run() == FALSE) 
     { 
      $data['title'] = "User Access"; 
      $data['author'] = "Salvatore Mazzarino"; 

      $this->load->view('templates/_header',$data); 
      $this->load->view('_login',$data); 
      $this->load->view('templates/_footer',$data); 
     } 
     else 
     { 
      redirect('home', 'refresh');    
     } 
    } 

    public function pass_check($pass) 
    { 
     $result = $this->user->find_user($this->input->post('username'),$pass); 

     if($result == 1) 
     { 
      $session_array = array(); 
      foreach ($result as $row) 
      { 
       $session_array = array('id'=> $row->id,'username'=> $row->username); /* Create a session passing user data */ 

       $this->session->set_userdata('logged_in',$session_array); 
      } 
      return TRUE; 
     } 
     else 
     { 
      $this->form_validation->set_message('pass_check',"Invalid username or password!</br>Try again, please!"); 
      return FALSE; 
     } 
    } 
} 

這行

$this->session->set_userdata('logged_in',$session_array); 

導致錯誤:

PHP Fatal error: Call to a member function set_userdata() on a non-object 

有人能說我的原因?

回答