這使我瘋狂......Jamie的Codeigniter MY_Model
我有CI 2.1.3的全新安裝。
複製MY_Model從這裏:https://github.com/jamierumbelow/codeigniter-base-model 到application/core。
自動加載數據庫庫autoload.php
配置的config文件夾內爲database.php正常。
擴展的MY_Model類象下面這樣:
class User_m extends MY_Model{
public $_table = 'user';
public $primary_key = 'user_id';
}
而且在默認控制器:
$this->load->model('user_m', 'user');
$row = $this->user->get(1);
echo $row->email;
這是我怎麼看的CRUD LIB作品,但得到以下錯誤最簡單的實現:
Fatal error: Call to a member function where() on a non-object in MY_Model.php on line 135
線MY_Model.php 135:
$row = $this->_database->where($this->primary_key, $primary_value)
->get($this->_table)
->{$this->_return_type()}();
嘗試它而不重命名模型:'$ this-> user_m-> get(1);' - 可能是擴展模型不支持重命名。 – swatkins 2013-03-03 14:42:10
試過了。沒有運氣.. – mallix 2013-03-03 14:44:48
該類的_set_database函數一定有問題。我不知道爲什麼那個函數在那裏,因爲你可以從CI配置文件加載數據庫。 – mallix 2013-03-03 15:10:58