CodeIgniter 4 how to load a model in the controller?
In this article we are seeing the how to load a model in the controller
Models are typically stored in the app/Models directory. They should have a namespace that matches their location within the directory, like namespace App\Models.
You can access models within your classes by creating a new instance or using the model() helper function.
<?php
// Create a new class manually.
$CommonModel = new \App\Models\CommonModel();
// Create a shared instance of the model.
$CommonModel = model('CommonModel');
// or
$CommonModel = model('App\Models\CommonModel');
?>
You can access model in the controller below like this