Best practices for loading models in controllers in CI 4? |
No need to use "as" since the names of the models do not clash with the controller class name. Anyway, your approach of using the "new" keyword is one of the approaches possible. You can also use the "model()" function if you want to load the same instance of your model everywhere you need it.
In your code, if you will be using the model function you can also skip the use statements for the models. You can use either: $this->someModel = model('Some_model'); $this->someOtherModel = model('Some_other_model'); If you want, you can also use the full qualified name if your models are namespaced. model('App\Models\SomeModel'); |
Messages In This Thread |
Best practices for loading models in controllers in CI 4? - by t_5810 - 09-22-2020, 04:46 PM
RE: Best practices for loading models in controllers in CI 4? - by nc03061981 - 09-23-2020, 02:18 AM
RE: Best practices for loading models in controllers in CI 4? - by paulbalandan - 09-23-2020, 02:57 AM
RE: Best practices for loading models in controllers in CI 4? - by t_5810 - 09-24-2020, 05:04 PM
RE: Best practices for loading models in controllers in CI 4? - by boddah85 - 10-21-2020, 12:35 PM
|