2017-07-01 74 views
0

我怎樣才能解決這個問題。當我運行這段代碼我收到以下錯誤我已經加載了會議庫還是我收到此錯誤
這是我的控制器

public function __construct(){ 
    parent::__construct();   
} 
public function index() { 
    $this->load->database(); 
    $this->load->helper('form', 'url'); 
    $this->load->library('session'); 
} 
public function process() {  
    $this->load->model('login_model'); 
    $result = $this->login_model->validate(); 
    if (!$result) { 
     $msg = '<font color=red>Invalid username and/or password.</font><br />'; 
     $this->load->view(base_url().'index',$msg); 
    } else { 
     if ($_SESSION['utype'] == 2 || $_SESSION['utype'] == 1) { 
      redirect(base_url() . 'admin/dashboard'); 
     } 
     if ($_SESSION['utype'] == 3 && !empty($_POST['urlValue'])) { 
      redirect($_POST['urlValue']); 
     } 
     if (empty($_POST['urlValue'])) { 
      redirect('/'); 
     } 
    } 
} 

這是我的模型

public function validate() { 
    $username = $this->security->xss_clean($this->input->post('email')); 
    $password = $this->security->xss_clean($this->input->post('password'));    
    $pwd = base64_encode($password); 
    $this->db->where('email', $username); 
    $this->db->where('password', $pwd);  
    $query = $this->db->get('adduser'); 
    $row = $query->row(); 

    if (count($row) > 0) {   
     $row = $query->row(); 
     $data = array(
      'uid' => $row->id, 
      'uname' => $row->firstname, 
      'utype' => $row->usertype, 
      'uemail' => $row->email, 
      'validated' => true 
     ); 
     $this->session->set_userdata($data); 
     return $row; 
    }  
    return $row; 
} 

我得到這個問題:

Severity: Notice 
Message: Undefined property: Index::$session 
Filename: core/Model.php 
Line Number: 77 
Backtrace: 
File: D:\xampp\htdocs\savepaise\application\models\Login_model.php 
Line: 42 
Function: __get 
File: D:\xampp\htdocs\savepaise\application\controllers\Index.php 
Line: 31 
Function: validate 
File: D:\xampp\htdocs\savepaise\index.php 
Line: 315 
Function: require_once 
Fatal error: Call to a member function set_userdata() on a non-object in 
D:\xampp\htdocs\savepaise\application\models\Login_model.php on line 42 
    A PHP Error was encountered 
Severity: Error 
Message: Call to a member function set_userdata() on a non-object 
Filename: models/Login_model.php 
Line Number: 42 
+0

我認爲你需要不加載控制器構造函數中所有圖書館索引功能 – JYoThI

+0

在您的文章中autoload.php –

+0

編輯格式添加會話庫。你的問題題目太長,問題代碼不正確。和你的問題的文本是不正確的 – mshomali

回答

1

我想你不僅需要在index function

public function __construct(){ 
    parent::__construct(); 
    $this->load->database(); 
    $this->load->helper('form', 'url'); 
    $this->load->library('session');   
} 

更新1加載all librarycontrollerconstructor函數內部:你可以使用自動加載這樣

轉到applications/config/autoload.php,並在那裏你可以編輯什麼你需要。

它們位於數組中,由包,庫,幫助程序,配置,語言和模型分隔。

$autoload['libraries'] = array('database', 'session'); 

$autoload['helper'] = array('url', 'html', 'form'); 
+0

這也是我已經嘗試,但它不工作 – Jani

+0

現在是什麼錯誤? – JYoThI

+0

謝謝JYoThI,在添加這個$ autoload ['libraries'] = array('database','session');現在正在工作 – Jani