简体   繁体   English

使用wanwizard datamapper时,在codeginiter帮助程序文件中调用模型类对象

[英]call model class object in codeginiter helper file while using wanwizard datamapper

While trying to access a user class object from codeigniter helper file, its throwing error like Class 'User' not found . 尝试从codeigniter帮助程序文件访问用户类对象时, Class 'User' not found其抛出错误,如Class 'User' not found My code is something like $u = new User(); $u->get(); 我的代码类似于$u = new User(); $u->get(); $u = new User(); $u->get(); I am able to use this in library files but not in helper files. 我可以在库文件中使用此功能,但不能在助手文件中使用此功能。 Can somebody help me. 有人可以帮我吗。

In order to use model in helper you have to: 为了在助手中使用模型,您必须:

// 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();

hope it will help! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM