我使用笨我的項目,我有這個類模式,我稱之爲創看起來像這樣:如何繼承其他模型的模型在笨
class Genesis_model extends CI_Model {
function __construct() {
parent::__construct();
}
function get() {
return 'human soul';
}
}
和我有另一種模式,存儲在相同的目錄,其延伸Genesis_model
class Human_model extends Genesis_model {
function __construct() {
parent::__construct();
}
function get_human() {
return $this->get();
}
}
Human_model用於由人力控制器
class Human extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('human_model');
}
function get_human() {
$data['human'] = $this->human_model->get_human();
$this->load->view('human/human_interface', $data);
}
}
如果我執行代碼,它會產生一個錯誤,指向返回$ this-> get()。它讀取「致命錯誤:Class'Genesis_model'在第2行的... \ application \ models \ human_model.php中未找到」。
我使用這種方法,因爲幾乎我所有的模型共享幾乎相同的結構。我收集了Genesis中的類似功能,而其他模型僅作爲它們所代表的表格的獨特數據供應商。它在我的asp.net(vb.net)中運行良好,但我不知道如何在codeigniter中執行此操作。
有沒有一種方法讓Human_model繼承Genesis_model。我不認爲我可以使用include('genesis_model.php')。我不知道它是否有效。
在此先感謝。
有趣的答案在這裏http://stackoverflow.com/questions/46338/can-you -access-a-model-from-inside-another-model-in-codeigniter – steve