从另一个模型加载和使用Codeigniter模型 [英] Loading and using a codeigniter model from another model

查看:90
本文介绍了从另一个模型加载和使用Codeigniter模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用codeigniter 1.7.3的资深编码人员,可以从另一个模型的代码中加载一个模型吗?我读过许多理论和实践文章,但没有一个给出最终答案.

Fellow coders, using codeigniter 1.7.3 can I load a model from the code of another model? I have read many posts theoretical and practical but none gave a final answer.

我有一个模型,该模型具有要在另一个模型上执行操作的功能.代码是这样的:

I have a model that has a function in which i would like to perform an operation on another model. the code is like this:

1: $this->load->model('decision_model');
2: $this->decision_model->hello_decision();  

第1行有效.第2行失败,如下所示:

line 1 works. line 2 fails as follows:

遇到PHP错误
严重性:通知
消息:未定义的属性:Account_model :: $ decision_model
文件名:models/account_model.php

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Account_model::$decision_model
Filename: models/account_model.php

我曾尝试创建简单的哑模型,更改函数名称,在加载模型时为其提供别名等...没有运气

I have tried creating simple dumb models, changed function names, giving the model an alias when loading it, etc... no luck

那么,从理论上讲,这可行吗?

So, theory aside, is this doable?

提前谢谢.

推荐答案

您可以这样做:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆