Loading and using a codeigniter model from another model Loading and using a codeigniter model from another model codeigniter codeigniter

Loading and using a codeigniter model from another model


You can do it like this:

class User_model extends Model{    function get_something()    {         $CI =& get_instance();         $CI->load->model('profile_model');         return $CI->profile_model->get_another_thing();    }}


In CI 2.0 you can just call one model directly from another.


You can also add a private $_ci; class variable, and initialize it in your constructor.

public function __construct($input=null){    $this->_ci =& get_instance();    if ( $input != null && is_array($input) ) {         $this->populate($input);    }}

Then it'll be available to any function you're working with, no need to get_instance() all over the place.