Welcome Guest, Not a member yet? Register   Sign In
Best practices for loading models in controllers in CI 4?
#3

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');
Reply


Messages In This Thread
RE: Best practices for loading models in controllers in CI 4? - by paulbalandan - 09-23-2020, 02:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB