We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



12.2k

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.