2014-09-29 210 views
1

我有這些模型:如何從主構造函數將參數傳遞給父構造函數?

class Content_model extends MY_Model{ 

    public function __construct() 
    { 
     $test='main_content'; 
     parent::__construct($test); 
    } 
} 

class MY_Model extends CI_Model { 

    public function __construct($recived_parameter) { 
     parent::__construct(); 
     // do something with $recived_parameter 
    } 

} 

我想爭論$test傳遞給MY_Model的結構,但似乎沒有被recived。有任何想法嗎?

+0

這2類不是關係所有.. – ngakak 2014-09-29 11:10:40

回答

1

水木清華這樣可能會奏效

class Content_model extends CI_Model{ 

    protected $param = "Haloo"; 

    public function __construct() 
    { 
     parent::__construct(); 
    } 
} 

class MY_Model extends Content_model { 

    public function __construct() { 

    echo $this->param; 
    } 

} 
相關問題