2012-02-16 54 views
6

我有此控制器:調用未定義的方法是CI_Controller ::控制器()

class Start extends CI_Controller{ 
    var $base; 
    var $css; 

    function Start() 
    { 
     parent::Controller(); //error here. 
     $this->base = $this->config->item('base_url'); //error here 
     $this->css = $this->config->item('css'); 

    } 

    function hello($name) 
    { 
    $data['css'] = $this->css; 
    $data['base'] = $this->base; 
    $data['mytitle'] = 'Welcome to this site'; 
    $data['mytext'] = "Hello, $name, now we're getting dynamic!"; 
    $this->load->view('testView', $data); 
    } 
} 

它告訴我在這一行:

父::控制器(); //錯誤在這裏。

Call to undefined method CI_Controller::Controller() 

如果我刪除line..I得到一個錯誤,指出下一行..

Call to a member function item() on a non-object 

我如何避免這樣的錯誤形式發生?

回答

24

之間的一個主要區別。如果你使用CI 2.X那麼你的類的構造函數應該是這樣的:

public function __construct() 
    { 
     parent::__construct(); 
     // Your own constructor code 
    } 

閱讀更多user guide

+0

謝謝你,現在工作 – BlackFire27 2012-02-16 16:12:21

相關問題