Welcome Guest, Not a member yet? Register   Sign In
Access $request in __construct in ResourceController?
#2

If I'm not mistaken, ResourceController and ResourcePresenter both extend CodeIgniter/Controller. So the request object is not accessible in the __construct but on the initController method.

In your class extension of the ResourceController, for example ApiController, you would have something like this:
PHP Code:
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
{
    
parent::initController($request$response$logger);

    
$data $this->request->getRawInput();

    
// If you want $data to be accessible in other places of the class, you might want to set it as a property instead. Then set it like:
    
$this->data $this->request->getRawInput();

Reply


Messages In This Thread
RE: Access $request in __construct in ResourceController? - by paulbalandan - 12-17-2020, 08:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB