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') {
$url = 'http://localhost/curl_logging/curlLogging.php';
$router = new \Phalcon\Mvc\Router();
$uri = $router->getRewriteUri();
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
$params = array();
$params['controller'] = $controller;
$params['action'] = $action;
calling_func($url, $params);
}
Thanks in advance.
The same way, you get your raw body:
if ($event->getType() == 'beforeDispatchLoop') {
$request = $this->di->getRequest();
// or
// $request = $this->di->get('request');
// $request = new \Phalcon\Http\Request();
// straight from $_POST
$user = $request->getPost('login');
// using filter for delivered data
$email = $request->getPost('email', 'email');
// just obtaining full $_POST
$form = $request->getPost();
}
Further information available under request documentation.