CodeIgniter Forums
Method chaining onto $this->load->model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Method chaining onto $this->load->model (/showthread.php?tid=65501)



Method chaining onto $this->load->model - seanloving - 06-19-2016

Used to be in CI2 I could do this:
$this->load->model('cat_model')->meow();

Was that bad practice?

Because it seems like CI3 is making me separate these:
$this->load->model('cat_model');
$this->cat_model->meow();

Or am I doing something wrong in CI3 (PHP 5.4) ?


RE: Method chaining onto $this->load->model - knightar - 06-20-2016

Taking a look at the source code for the Loader class, I'm assuming in CI2 it returned the model, but in CI3 it actually returns the loader, so you will be able to chain the loader functions IE $this->load->model('cat_model')->library('form') etc. You will always have to use $this->cat_model syntax in CI3.