使用wand向导数据映射器时,在codeigniter帮助文件中调用模型类对象

时间:2013-04-02 06:34:08

标签: php mysql codeigniter-2 datamapper

尝试从codeigniter帮助文件访问用户类对象时,其抛出错误如Class 'User' not found。我的代码是这样的     $u = new User(); $u->get(); 我可以在库文件中使用它,但不能在辅助文件中使用它。有人可以帮助我。

1 个答案:

答案 0 :(得分:1)

为了在助手中使用模型,你必须:

// Get a reference to the controller object
$CI = get_instance();

// You may need to load the model if it hasn't been pre-loaded
$CI->load->model('User');

// Call a function of the model
$CI->User->get();
希望它会有所帮助!