Access $request in __construct in ResourceController? |
How do I access the $request in the __construct of a ResourceController?
I've tried: Code: $data = $request->getRawInput(); // Crashes with Internal Server Error
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 $request, ResponseInterface $response, LoggerInterface $logger)
Yes, that's why I hate that the CI team 'broke' __construct. We've all grown used to being able to use it like we expect to. And now, all of a sudden we have to 'adapt' to these weird custom approaches ... it's NOT good.
If I add your code ... my ResourceController just breaks! WHAT am I supposed to be doing with it? And WHY do I have to 'extend' a Controller in order to have access to the $request? It doesn't make ANY sense to me, at all! Had to add this: public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) But it still seems annoying and cumbersome to have to make all this basic stuff ... in order to access the request ... now when would a Controller NOT have a request? I cannot see the case for leaving this out. |
Welcome Guest, Not a member yet? Register Sign In |