Пример #1
0
 public function postDispatch(Request $req, Response $res)
 {
     $controller = strtolower(str_replace('_', '/', $req->controller));
     $action = strtolower(str_replace('_', '-', $req->action));
     $path = isset($req->view->path) ? $req->view->path : "{$controller}/{$action}";
     $isJson = $req->isAjax() && count((array) $req->data);
     $isNotify = $req->isAjax() && !isset($req->data->redirect);
     if ($isNotify) {
         $req->data->notifications = $this->notify->notifications();
     }
     if ($isJson) {
         return $res->json($req->data);
     }
     return $res->header('X-JSON', json_encode($req->data))->html($this->view->render($path, ['req' => $req, 'res' => $res] + (array) $req->view, $req->group));
 }