Post data in services.php

Hi,

We can access post data in controller something like this, $request = $this->di->get("request"); $data = $request->getJsonRawBody(); But is there any way to access POSt data in services.php. I wanted to access it in an event, if ($event->getType() == 'beforeDispatchLoop') {}

Thanks in advance.



6.5k

In services.php, you do have a $di variable.

So you could use:


$request = $this->request;      // $this = $di

within whatever configured service you have:


$di->setShared('dispatcher', function() {
// code
$request = $this->request;

});

Just access request as always.