のCodeIgniter 3.1.3ではIは、アプリケーション/コア/ MY_Model.phpでCI_Modelを拡張:
class MY_Model extends CI_Model {
public function __construct($id = NULL) {
parent::__construct();
$this->load($id);
}
public function load($id) {
$this->db->where('id', $id);
$this->db->limit(1);
$query = $this->db->query($this->_table);
if ($row = $query->result()) {
// @todo Process results
}
// Free the resources.
$query->free_result();
}
}
マイUser_modelは次のようになります。
class User_model extends MY_Model {
public function __construct($id = NULL) {
parent::__construct($id);
}
}
私も拡張アプリケーション/コア/ MY_ControllerのCI_Controllerを次のように入力します。
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('User_model');
}
}
私はアプリケーションでデータベース接続を自動ロードしましたエーション/設定/ autoload.phpとして:
$autoload['libraries'] = array('database');
データベース接続が正しく設定されているので、私は、移行を実行することができたコントローラでUser_modelをロードせず。しかし、$ this-> load-> model( 'User_model')を追加すると、 "Undefined property:User_model :: $ db"というエラーが出ます。
User_modelをCI_Modelに拡張させると、エラーなしで実行され、ホームページのコントローラのvar_dumpでデータベースが正しく自動ロードされていることが示されます。しかし、間にMY_Modelを置くとすぐに、データベースクラスはモデルでは未定義で、モデルの$ this-> loadもNULLを返します。そのため、モデルが正しく構築されていないようです。
私はこれが非常に小さな間違いであると想像することができますが、私は何時間もそれを見ていて何度も休憩しています。私はそれを見ません。誰かが私を助けることができますか?コントローラから