Ste*_*ran 45
您可以获得对控制器对象的引用并通过它访问模型.
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();
}
Run Code Online (Sandbox Code Playgroud)
另一种选择是在调用辅助函数时传递模型.
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22979 次 |
| 最近记录: |