解决方法是先在派生类中包含父模型的定义文件。
用户_型号
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Users_Model extends CI_Model {
public function __construct(){
echo("<hr><pre> L: ".__LINE__." :: :: F: ".__FILE__ . ' M: '.__METHOD__ . ' ' . date('H:i:s').' ( ) '."</pre>\n" . get_class($this) );
}
}
/* End of file Users_Model.php */
/* Location: ./application/models/Users_Model.php */
学生_模特
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once(APPPATH . 'models/Users_Model.php');
class Students_Model extends Users_Model {
private $_students;
public function __construct(){
parent::__construct();
echo("<hr><pre> L: ".__LINE__." :: :: F: ".__FILE__ . ' M: '.__METHOD__ . ' ' . date('H:i:s').' ( ) '."</pre>\n" . get_class($this));
}
}
/* End of file Students_Model.php */
/* Location: ./application/models/Students_Model.php */
测试用例
包括某处
$this->load->model('Students_Model');
结果
L: 9 :: :: F: /www/application/models/Users_Model.php M: Users_Model::__construct 23:16:34 ( )
Students_Model
L: 14 :: :: F: /www/application/models/Students_Model.php M: Students_Model::__construct 23:16:34 ( )
Students_Model
截屏
附录
为了在您的设计中获得更多结构,您可能决定将这 2 个类放到一个子文件夹models/people
中。然后修改如下:
include_once(APPPATH . 'models/people/Users_Model.php');
$this->load->model('people/Students_Model');