CodeIgniter Forums
Model / Controller access - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Model / Controller access (/showthread.php?tid=78268)



Model / Controller access - newbie_to_ci - 12-25-2020

Fairly new to using CI, and this is probably a stupid question, but I figured I'd ask, because the answer didn't seem 100% apparent to me.




What is the proper  way of globally initiating a new model for use throughout a controller ?   or do I need to do a $model = new someModelname();  in each function that I want to access the model from ?

Do I just drop it in something like the index function, and call it from my other functions using $this->index()->model->SomeModelFunction   



Thanks,


RE: Model / Controller access - John_Betong - 12-25-2020

Take a look at this documentation article and learn how to extend every controller and make variables and methods available in every inherited controller:

https://www.codeigniter.com/user_guide/extending/basecontroller.html?highlight=base%20controller


RE: Model / Controller access - newbie_to_ci - 12-25-2020

(12-25-2020, 04:59 PM)John_Betong Wrote: Take a look at this documentation article and learn how to extend every controller and make variables and methods available in every inherited controller:

https://www.codeigniter.com/user_guide/extending/basecontroller.html?highlight=base%20controller

Well damn... I missed that in the documentation..   Now I feel silly...  lol    Thank you !