Search code examples
codeignitermodel

Codeigniter Model extends CI_MODEL


I want to create 2 different models extends CI_Model in core folder, for example:

class MY_FirsModel extends CI_Model {

}

class MY_SecondModel extends CI_Model {

}

Is it possible when using codeigniter?


Solution

  • According to Codeigniter's Documentation, when extending a core class, you need to give the same name to your class, only changing CI_ by MY_.

    When the loader class is fetching all core classes it looks for specific matching names such as Model, Controller, Exceptions and so on. It starts looking by the application/core folder, with prefixes MY_ and then goes to system/core if a extended class was not found.

    If you need to maintain the names MY_FirsModel and MY_SecondModel, you can create these models in the application/libraries folder and the require these files in the classes you will use them.

    require_once APPPATH.'libraries/MY_FirsModel.php';
    

    and

    require_once APPPATH.'libraries/MY_SecondModel.php';