我知道这听起来所以转贴好几次。但我无法解决它。
我尝试将我的应用程序连接到 mysql,这些是我尝试过的(我只尝试了这些选项中的一个,而不是两个):
$autoload['libraries'] = array('database');
开application\config\autoload.php
,但我得到了Fatal error: Call to a member function get() on a non-object in /Users/zakkafm/Sites/CodeIgniter/application/models/My_models.php on line 15
$this->load->database();
onapplication\models\My_models.php
on__construct()
(我也添加了parent::__construct()
,但我得到了Fatal error: Call to a member function database() on a non-object in /Users/zakkafm/Sites/CodeIgniter/application/models/My_model.php on line 7
那么,这里有什么问题呢?
编辑:这是我的database.php
样子。
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'trial';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
解决!!!
毕竟,这都是因为我在 Eclipse 上添加的自动完成功能system/core/Controller.php
和system/core/Model.php
.