public function beforeDispatch(Event $event, Dispatcher $dispatcher) { $di = $this->getDI(); $request = $di->get('request'); if (!$dispatcher->wasForwarded()) { if ($request->has($this->method_key)) { $method = $request->get($this->method_key); } else { $method = $request->getHeader('X-HTTP-Method-Override'); } if (!empty($method)) { $dispatcher->forward(['action' => $method]); } } if ($request->has($this->format_key)) { $mime = 'application/' . $request->get($this->format_key); } else { $parts = explode(';', $request->getHeader('Accept')); $mime = reset($parts); } if (empty($mime) || $mime == '*/*') { $mime = 'application/json'; } $rest = $di->get('rest'); $rest->setFormat($mime); }
public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher) { /** @var \Phalcon\Mvc\Router $route */ $route = $dispatcher->getDI()->get('router'); $view = $dispatcher->getDI()->getService('view')->resolve(); $wasForwarded = $dispatcher->wasForwarded(); if ($wasForwarded) { return; } if ($route->getMatchedRoute()) { $paths = $route->getMatchedRoute()->getPaths(); $controller = $paths['controller']; $action = \Phalcon\Text::uncamelize($paths['action']); $action = str_replace("_", "-", $action); $template = $controller . '/' . $action; $view->pick([$template]); } }