如何在调度循环phalcon之前获取post参数

时间:2016-08-12 07:51:46

标签: phalcon phalcon-routing phalconeye

我们可以在控制器中访问帖子数据,如下所示:

$request = $this->di->get("request");
$data = $request->getJsonRawBody();

但有没有办法在services.php中访问POST数据。我想在一个事件中访问它:

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);
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

同样地,你得到了你的生体:

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();
}

request documentation下的更多信息。