09-18-2020, 08:50 PM
I have a model that performs some operations in my database. We'll call it "Somemodel". There's a method I want to use called "somemethod($value)" in the Somemodel model. I'd like to include this model and call that method in every controller. I know that I can modify the BaseController, and all my controllers should extend BaseController. Can someone show me an example of what that looks like? The documentation shows using a Session service. So, what does the code look like to load one of my models?
Code:
// Do Not Edit This Line
parent::initController($request, $response, $logger);
//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
// $this->session = \Config\Services::session();
$session = \Config\Services::session($config); // I like this!
// How do I load one of my models and use a method? What does that code look like?