/** * Initialize the request. If adapter is null, * Pfw_Request_Standard will be used. * * @param string $adapter the adapter class */ public static function init($adapter = null) { if (!is_null($adapter)) { self::$adapter = $adapter; } else { $adapter_class = "Pfw_Request_Standard"; Pfw_Loader::loadClass($adapter_class); self::$adapter = new $adapter_class(); } }
function setupView() { $view = $this->getView(); $view->assign('controller', Pfw_Request::getParam('controller')); if (self::is_logged_in()) { # gettng user with profile photo Pfw_Loader::loadModel('User'); $user = User::Q()->where(array('this.id = %s', Pfw_Session::get('login_id')))->exec(); $logged_in_user = $user[0]; $view->assign('logged_in_user', $logged_in_user); $view->assign('is_logged_in', true); } }
/** * Returns true if request was ajax. * NOTE - Only works if the javascript library sends the X_REQUESTED_WITH * header. * * @return bool */ public function isAjax() { return Pfw_Request::isAjax(); }
/** * Routes the request through the router with assigned routes * * @param array $routes */ public function dispatch() { Pfw_PluginManager::execPreRoute(); $script_url = $_SERVER['REQUEST_URI']; if (false !== ($qpos = strpos($script_url, '?'))) { $script_url = substr($script_url, 0, $qpos); } $route_params = $this->getRouter()->route($script_url); Pfw_Request::setParams($route_params); if (empty($route_params)) { Pfw_Loader::loadClass('Pfw_Exception_NoRoute'); throw new Pfw_Exception_NoRoute("Failed to find matching route for url path: '{$script_url}'"); } Pfw_PluginManager::execPostRoute(); $module = isset($route_params['module']) ? $route_params['module'] : null; Pfw_PluginManager::execPreMap(); $cont_action = $this->getMapper()->map($route_params['controller'], $route_params['action'], $module); Pfw_PluginManager::execPostMap(); Pfw_PluginManager::execPreDispatch(); $controller = $cont_action['controller']; $method = $cont_action['method']; $controller->_setFrontController($this); $this->controller = $controller; $controller->{$method}(); Pfw_PluginManager::execPostDispatch(); }