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

Hello

In CI 3 I have loaded the models that I need in my controllers like this:

Code:
public function __construct()
    {
        parent::__construct();
        $this->load->model('Some_model');
        $this->load->model('Some_other_model');
    }   // End of constructor function

Now, in CI 4, I am using the following code:

Code:
use App\Models\SomeModel;
use App\Models\SomeotherModel;
    class Myclass extends Backendcontroller
    {

        public function __construct()
        {
            $this->someModel = new SomeModel();
            $this->someOtherModel = new SomeotherModel();
        }


$foo = $this->someModel->where('bar', $bar)->findAll();

My question is: Can this be considered best practice? Can anyone point better way for loading models that I need to use in my controllers? 

Any advice would be deeply appreciated.
Reply


Messages In This Thread
Best practices for loading models in controllers in CI 4? - by t_5810 - 09-22-2020, 04:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB