Welcome Guest, Not a member yet? Register   Sign In
IDEA: Controller Extended by Default
#8

@kilishan I had to fully-namespace the type hints and pass the parameters to the parent class:

PHP Code:
    public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        
parent::initController($request$response$logger); 

I'm curious about your comment "Autoload any models, libraries, etc, here." - since there's no super-object anymore, what does loading anything in the base do, as it won't be accessible to the children controllers? Or is the thought to create protected variables to receive the objects? E.g.:

protected $userModel;

In initController:
$this->userModel = new UserModel();

Then in any Controller that extends BaseController:

$user = $this->userModel->find($userid);

... or am I missing something?
Reply


Messages In This Thread
IDEA: Controller Extended by Default - by MGatner - 03-18-2019, 07:28 AM
RE: IDEA: Controller Extended by Default - by MGatner - 03-20-2019, 08:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB