【问题标题】:How to load a model from another module with CodeIgniter如何使用 CodeIgniter 从另一个模块加载模型
【发布时间】:2010-06-28 21:04:21
【问题描述】:

我使用带有 CodeIgniter 的 HMVC 扩展,我得到了 2 个模块

modules/frontpage
  -- controllers
    frontpage.php ( <- this controller needs to load the person model)
  -- models
  -- views
modules/person
  -- controllers
  -- models
    person_model.php ( defines Person_Model extends Model )
  -- views

在首页控制器内使用$this-&gt;load-&gt;model('person_model') 似乎只加载全局或包含在同一模块中的模型(首页模型)。

这里有 CodeIgniter 专家吗?

【问题讨论】:

    标签: codeigniter model module


    【解决方案1】:

    找到它...这是一个简单的修复。

    只需要使用:$this-&gt;load-&gt;model('person/person_model');

    【讨论】:

      【解决方案2】:

      根据我在另一个版本的 codeigniter 中的经验,加载模型的正确方法是 $this->load->model($model = 'person', $module = 'person');

      【讨论】:

        【解决方案3】:
        $rand=rand(1,9999999);
        $currentModel="currentModel".$rand;
        $this->load->model($call_model,$currentModel);
        $call_method=$method;            
        $currentMod=$currentModel;
        $CI =& get_instance();
        $re_data= $CI->$currentMod->$call_method($paramArr);
        

        【讨论】:

          猜你喜欢
          • 2011-06-05
          • 1970-01-01
          • 1970-01-01
          • 2016-07-27
          • 1970-01-01
          • 2013-07-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多