如何在CodeIgniter中继承另一个模型的模型 [英] How to Inherit A Model from Another Model in CodeIgniter

查看:443
本文介绍了如何在CodeIgniter中继承另一个模型的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用codeigniter为我的项目,我有这个类模型,我调用Genesis,看起来像这样:

i'm using codeigniter for my project and i have this class model which i call Genesis which looks like this:

class Genesis_model extends CI_Model {
    function __construct() {
        parent::__construct();
    }

    function get() {
        return 'human soul';
    }
}

我有另一个模型,存储在同一个目录,它扩展了Genesis_model

and i have another model, stored in the same directory, which extends Genesis_model

class Human_model extends Genesis_model {
    function __construct() {
        parent::__construct();
    }

    function get_human() {
        return $this->get();
    }
}

Human_model由Human controller使用

Human_model is used by Human controller

class Human extends CI_Controller {     
    function __construct(){
        parent::__construct();
        $this->load->model('human_model');
    }       

    function get_human() {
        $data['human'] = $this->human_model->get_human();
        $this->load->view('human/human_interface', $data);
    }
}

如果我执行代码,它指向 return $ this-> get()。它读取致命错误:类'Genesis_model'中找不到... \application\models\human_model.php在第2行。

if i execute the code, it will produce an error which point to return $this->get(). it reads "Fatal error: Class 'Genesis_model' not found in ...\application\models\human_model.php on line 2".

我使用这种方法,因为几乎所有的模型共享几乎相同的结构。我在Genesis中收集类似的功能,而其他模型只能作为它们所代表的表的唯一数据提供者。它在我的asp.net(vb.net)工作良好,但我不怎么做它在codeigniter。

i use this method because nearly all my models shared almost identical structure. I gather the similar functionality in Genesis while the other models serve only as data suppliers unique to the tables they represent. it works well in my asp.net (vb.net) but i don't how to do it in codeigniter.

有一种方法为Human_model继承Genesis_model。我不认为我可以使用 include('genesis_model.php')。我不知道它是否工作。

is there a way for Human_model to inherit Genesis_model. i don't think i'm allowed to use include('genesis_model.php'). i don't know if it works either.

提前感谢。

推荐答案

将文件genesis_model.php放在核心目录

Put the file genesis_model.php in the core directory

这篇关于如何在CodeIgniter中继承另一个模型的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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