CodeIgniter Forums
Global model - 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: Global model (/showthread.php?tid=73626)



Global model - Piotr - 05-15-2019

Hello

In CI3 i have one model that i have used as my main model (he holds all config, useful functions, there was html title of the page and other stuff) in any other model, controller or even view i can call this model and use functions or set properties.

Now in CI4 i have problem with this. My question is: How to make one model that is visible under all models? Is there any solution to not to load my model any time when i want to use it ?
There is solution for one "main model" that is visible to all models?

Thank you for reply


RE: Global model - kilishan - 05-15-2019

A couple of ideas:

1. You could extend all models from your own BaseModel that instantiates that other model and makes it available.
2. You could create a Service for that model so that only a single instance is always loaded whenever you call it.

Though, honestly, it sounds like that should be a library not a model, if you ask me.