Search for Resources and Solutions

How to change the CodeIgniter default models locations

Please stay away from my models! Don't use them for your apps, components, plugins or themes because i can change them in a day. If you want to use the database in your apps, components, plugins or themes, please create your own models.

If you want to create a model, create the directory models in your plugin, theme, component or app. Then you have to know the path of your plugin, theme, component or app.

If you know the path, before call a model's method, use this:




// Get codeigniter object instance
$CI =& get_instance();

// Load Base Model
$CI->load->ext_model( YOUR_PATH . 'models/', 'Your_model', 'your_model' );


As you can see, first parameter is the PATH, second is the model's class and third is the name used to call the model:


$CI->your_model->yourethod();

In this way you can use the models wherever you want.

Was this article helpful?