在CodeIgniter中,如何从另一个模型中访问一个模型? [英] In CodeIgniter, how do I access one model from within another?
本文介绍了在CodeIgniter中,如何从另一个模型中访问一个模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我在用户模型中的delete_user()函数中,我希望它在我的评论模型中使用delete_comment()函数。
Say I am in the delete_user() function in the user model, and I want it to use the delete_comment() function in my comment model.
直接访问注释表,或从我的控制器加载和调用其他模型,但为了保持我的代码尽可能抽象,我想能够从另一个模型中访问一个模型。
I could access the comment tables directly, or load and call the other model from my controller, but to keep my code as abstract as possible I want to be able to access one model from within another.
这是否可能与CodeIgniter?
Is this possible with CodeIgniter?
推荐答案
您需要这:
class User_model extends Model
{
function get_something()
{
$CI =& get_instance();
$CI->load->model('profile_model');
return $CI->profile_model->get_another_thing();
}
}
这篇关于在CodeIgniter中,如何从另一个模型中访问一个模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文