/** * Метод перехода к определенному контроллеру приложения: * $controller - имя контроллера. * $action - имя действия контроллера. */ public function go($controller, $action = 'index') { if (class_exists($controller . 'Controller')) { $template = new Template(); $ctrl_class = $controller . 'Controller'; $ctrl = new $ctrl_class($this, $template); if (@$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { if (method_exists($ctrl, $action . 'AjaxAction')) { $this->controller = $controller; $this->action = $action; $result = json_encode(call_user_func(array($ctrl, $action . 'AjaxAction'), $this)); } else { $result = json_encode(false); } $template->headerOk(); $template->headerNoCache(); $template->headerContentType('text/javascript', 'UTF-8'); die($result); } if (method_exists($ctrl, $action . 'Action')) { $this->controller = $controller; $this->action = $action; if (call_user_func(array($ctrl, $action . 'Action'), $this, $template)) { $ctrl->process($template); } return true; } throw new Exception('Controller ' . $controller . ' has no ' . $action . ' action!'); } throw new Exception('Application has no ' . $controller . ' controller!'); }