Extending Multiple Models in Codeigniter 2

How to configure CI2 to allow the extension of multiple models?

I can only get it for an extension of one model (type / application / core) named MY_Model (case sensitive).

To choose which model to expand, I do; in the model.

require_once APPPATH.'core/MY_Another_model.php';
class Test_model extends MY_Another_model {
...
}

I cannot find where in the kernel system code, where it indicates only to allow models that extend, to be called MY_Model.

Thanks for any help.

+5
source share
4 answers

, MY_Model. codeigniter, , MY_ ( ).

MY_Model, MY_Special_Model MY_Another_Model

+4

Cubed Eye, , :

autoload.php. MY_Model ( CI_Model), , , :

class Extended_model extends MY_Model {
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Another_model');
    }
}

(/Extended_model.php)

class Another_model extends Extended_model {
}

(/Another_model.php)

EDIT: , "" . , CI_ * (.. MY_Controller, MY_Model, MY_Input ..). , MY_Model, / "MY _".

+9

, load_class:

:
/ ​​/Special_model_class.php:

class CI_Special_model_class extends CI_Model {...}

php CI_, !

, /:
//one_model.php:

class One_model extends CI_Special_model_class {...}

, load_class :
//one_ctrl.php

....
load_class('Special_model_class', 'core');
$this->load->model('Special_model_class');
....

In the end, you can try calling load_classinside the model, right before defining it. application / models / one_model.php:

load_class('Special_model_class', 'core');
class One_model extends CI_Special_model_class {...}
+1
source

Here is the model's parent class:

class MY_Common_Model extends CI_Model {

    function __construct() {
        parent::__construct();
    }
        function drop_table($table_name) {
        $this->connect();
         $this->dbforge->drop_table($table_name);

    }

}

Here is the class of child models:

class MY_Model extends MY_Common_Model {
     function inset_table($table_name) {
        $this->connect();
        $this->insert_table($table_name);

    }
}

in the model:

 $this->drop_table($edge_table);
0
source

All Articles