0

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.

user1740757
  • 87
  • 1
  • 10

1 Answers1

0

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.

yergo
  • 4,761
  • 2
  • 19
  • 41
  • Hi thanks for the response. But if the post data is in json format, i wanted to get the whole data. not a specific node like mentioned 'email'. – user1740757 Aug 12 '16 at 08:27
  • 1
    @user1740757, Like you mentioned in your question: you can just use `$request->getJsonRawBody();` inside the `if`-statement. – Timothy Aug 12 '16 at 08:52