2011-11-04 115 views
0

我是codeigniter的新手,我在構造函數方法中加載模型時遇到了一些問題。有人可以幫我嗎?下面是從控制器我試圖加載從模型的代碼...加載時Codeigniter問題模型

<?php 

    class Login extends CI_Controller { 

     function Login(){ 
      $this->load->model('membership_model'); 
     } 

     public function index(){ 
      $this->load->view('login_view.php'); 
     } 

     public function authenticate(){ 
      $user = $this->input->post('username'); 
      $pass = sha1($this->input->post('password')); 
      if($user != null && $pass != null){ 
       $access = $this->membership_model->request_access($user, $pass); 
       if($access == true){ 
        $cookie = array(
         'name' => 'username', 
         'value' => $user, 
         'expire' => '86500', 
         'domain' => 'unleashourmedia.com', 
         'path' => '/', 
         'prefix' => '', 
         'secure' => TRUE 
        ); 

        $this->input->set_cookie($cookie); 
        echo "cookie"; 
       } else { 
        redirect('login'); 
       } 
      } 
     } 

    } 

?> 
+0

有什麼問題?任何錯誤消息? – Vikk

+0

你可以顯示你收到的錯誤信息是什麼? – Ghostman

回答

1

問題是你是不是調用父類的構造函數。

添加爲在構造函數的第一行:

parent::__construct(); 
0
function Login(){ 
    $this->load->model("membership_model","",TRUE); 
    } 
+0

我仍然得到相同的錯誤。還有什麼建議? –

+0

錯誤是什麼? – Ghostman

+0

這只是讓模型自動連接到數據庫,我沒有在這裏看到這樣做的重點(儘管我必須說問題根本不清楚什麼是問題_is_) –

0
//make sure you call parent constructor before anything in that constructor like this 
    function Login(){ 
     parent::__construct(); 
     $this->load->model('membership_model'); 
    } 

    //and you may also try to name the constructor __construct 
    function __construct(){ 
     parent::__construct(); 
     $this->load->model('membership_model'); 
    }