CodeIgniter 4 Models preloading |
You should preload components (like models, etc.) by using initController() as demonstrated here.
There is a controller named BaseController distributed with the framework that is included exactly for the purpose of doing what you want. Look closely at how initController() is defined in app\Controllers\BaseController. PHP Code: public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) Put your model loading in the commented section near the bottom. (Oh, and remove the comments.) It might look like this PHP Code: public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) Then extend any controllers that need this model from BaseController PHP Code: namespace App\Controllers; On a side-note: Please don't use Lightshot or the like to show code. Instead, copy & paste and surround the lines of code with [php] ...lines of code... [\php] tags. Thanks. |
Messages In This Thread |
CodeIgniter 4 Models preloading - by Aliton - 02-28-2020, 05:42 AM
RE: CodeIgniter 4 Models preloading - by dave friend - 02-28-2020, 02:44 PM
|