CodeIgniter Forums

Full Version: Global model
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.