如何将模型加载到帮助器? [英] How can I load model to helper?
本文介绍了如何将模型加载到帮助器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将模型加载到帮助程序?我需要将它加载到函数之外,但在函数中使用它们。
How can I load model to helper? I need to load it outside of functions, but use them in functions.
推荐答案
function my_helper()
{
// 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('my_model');
// Call a function of the model
$CI->my_model->do_something();
}
另一个选择是在调用辅助函数时传递模型。 p>
Another option is to pass the model in when calling the helper function.
function my_helper($my_model)
{
$my_model->do_something();
}
function my_controller_action()
{
// Call the helper function, passing in the model
my_helper($this->my_model);
}
这篇关于如何将模型加载到帮助器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文