We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Post data in services.php


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.


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.