/** * Processes the dispatch * * @return bool */ private function _process() { $this->_hasResult = $this->_router->getResult(); $this->_parameters = $this->_router->getParams(); if ($this->_parameters !== false) { $type = $this->_parameters["type"]; } if ($this->_hasResult === false) { $type = "error"; } return $this->_dispatch($type); }
function __construct($method, $messages) { $this->controller = new AppController(); $params = Router::getParams(); $viewPath = $this->controller->viewPath; if (Configure::read('App.theme')) { $viewPath = 'errors'; if ($this->controller->view == 'Theme') { $viewPath = 'themed' . DS . Configure::read('App.theme') . DS . 'errors'; } } if (Configure::read('debug') == 0) { $method = 'error404'; } $checkView = VIEWS . $viewPath . DS . Inflector::underscore($method) . '.ctp'; if (file_exists($checkView)) { $this->controller->_set(Router::getPaths()); $this->controller->viewPath = $viewPath; $this->controller->theme = $appConfigurations['theme']; $this->controller->pageTitle = __('Error', true); $this->controller->set('message', $messages[0]['url']); $this->controller->set('appConfigurations', $appConfigurations); $this->controller->render($method); e($this->controller->output); } else { parent::__construct($method, $messages); } }
/** * Starting point for every page request. Loads required core modules, gets data from url and calls * necessary modules to make things happen. */ public static function init() { if (!self::$_inited) { self::$_inited = true; foreach (self::$_requiredCore as $module) { require_once ROOT . 'core/' . $module . '/' . $module . EXT; } // Set the Load::auto method to handle all class loading from now on spl_autoload_register('Load::auto'); Load::loadSetupFiles(); // If CLI mode, everything thats needed has been loaded if (IS_CLI) { return; } date_default_timezone_set(Config::get('system.timezone')); Event::trigger('caffeine.started'); // If maintenance mode has been set in the config, stop everything and load mainteance view if (Config::get('system.maintenance_mode')) { View::error(ERROR_MAINTENANCE); } else { list($route, $data) = Router::getRouteData(); if ($data) { if (self::_hasPermission($route, $data)) { list($module, $controller, $method) = $data['callback']; $params = Router::getParams(); // Make sure controller words are upper-case $conBits = explode('_', $controller); foreach ($conBits as &$bit) { $bit = ucfirst($bit); } $controller = implode('_', $conBits); $controller = sprintf('%s_%sController', ucfirst($module), ucwords($controller)); // Call the routes controller and method if (method_exists($controller, $method)) { $response = call_user_func_array(array($controller, $method), $params); if (!self::_isErrorResponse($response)) { Event::trigger('module.response', array($response)); View::load($module, $controller, $method); } else { View::error($response); } } else { Log::error($module, sprintf('The method %s::%s() called by route %s doesn\'t exist.', $controller, $method, $route)); View::error(ERROR_500); } } else { View::error(ERROR_ACCESSDENIED); } } else { if ($route !== '[index]' || !View::directLoad('index')) { View::error(ERROR_404); } } } View::output(); Event::trigger('caffeine.finished'); } else { die('Why are you trying to re-initialize Caffeine?'); } }
public function execute() { $suffix = "Controller"; Router::parseUri(); try { $_cc = ucfirst(Router::getController()) . $suffix; Loader::autoload($_cc); if (!class_exists($_cc, false) && !interface_exists($_cc, false)) { throw new Exception('Class ' . $_cc . ' does not exist'); } $class = new ReflectionClass($_cc); if ($class->isAbstract()) { throw new Exception('Cannot create instances of abstract ' . $_cc . ''); } // Create a new instance of the controller $controller = $class->newInstance(); // Execute the "before action" method //$class->getMethod('before')->invoke($controller); // Execute the main action with the parameters $class->getMethod(Router::getAction() . 'Action')->invokeArgs($controller, Router::getParams()); // Execute the "after action" method //$class->getMethod('after')->invoke($controller); } catch (Exception $e) { throw $e; } return $this; }
/** * */ public function read_group($userSlug, $collectionSlug, $groupTypeSlug, $groupSlug) { $userId = $this->Users->getIdFromSlug($userSlug); $collectionId = $this->Collections->getIdFromSlug($collectionSlug); $collectionFieldId = $this->CollectionGroups->getFieldIdFromSlug($groupTypeSlug); $groupValue = $this->CollectionGroups->getFieldValueFromSlug($groupSlug); $user = $this->Users->getUser($userId); $this->set('user', $user); $collection = $this->Collections->getCollection($collectionId); $this->set('collection', $collection); $group = $this->CollectionGroups->getGroup($collectionFieldId, $groupValue); $this->set('collectionGroup', $group); $participation = $this->Participations->getCollectionForUser($userId, $collectionId); $this->set('participation', $participation); $itemIds = $this->CollectionGroups->getItemIds($collectionFieldId, $groupValue); $page = empty($this->request->query['page']) ? 0 : $this->request->query['page']; $items = $this->CollectionItems->getItems(null, $itemIds, $page); $this->set('collectionItems', $items); $this->set('collectionItemsPaging', Router::getParams()['paging']['CollectionItem']); $participations = $this->Participations->getUsersForGroup($collectionId, $collectionFieldId, $groupValue); $this->set('participations', $participations); $participationGroup = $this->ParticipationGroups->getGroup($userId, $collectionId, $group['CollectionGroup']['name']); $this->set('participationGroup', $participationGroup); $completions = $this->Completions->getCompletions($userId, $collectionId); $this->set('completions', $completions); $legendAvailability = $this->CollectionItems->getAvailabilityLegend(); $this->set('legendAvailability', $legendAvailability); $legendCompletion = $this->Completions->readCompletionLegend(); $this->set('legendCompletion', $legendCompletion); $this->set('collectionSlug', $collectionSlug); $this->set('groupTypeSlug', $groupTypeSlug); $this->set('groupSlug', $groupSlug); $this->set('groupValue', $groupValue); }
/** * */ public function read_collection($userSlug, $collectionSlug) { $userId = $this->Users->getIdFromSlug($userSlug); $collectionId = $this->Collections->getIdFromSlug($collectionSlug); $user = $this->Users->getUser($userId); $this->set('user', $user); $collection = $this->Collections->getCollection($collectionId); $this->set('collection', $collection); $participation = $this->Participations->getCollectionForUser($userId, $collectionId); $this->set('participation', $participation); $page = empty($this->request->query['page']) ? 0 : $this->request->query['page']; $items = $this->CollectionItems->getItems($collectionId, null, $page); $this->set('collectionItems', $items); $this->set('collectionItemsPaging', Router::getParams()['paging']['CollectionItem']); $participations = $this->Participations->getUsersForCollection($collectionId); $this->set('participations', $participations); $completions = $this->Completions->getCompletions($userId, $collectionId); $this->set('completions', $completions); $legendAvailability = $this->CollectionItems->getAvailabilityLegend(); $this->set('legendAvailability', $legendAvailability); $legendCompletion = $this->Completions->readCompletionLegend(); $this->set('legendCompletion', $legendCompletion); $this->set('userSlug', $userSlug); $this->set('collectionSlug', $collectionSlug); }
/** * Test getParams with multiple urls given in PATH_INFO * * @dataProvider getSamplePathInfoStrings */ public function testGetParams_MultipleUrlsInPathInfo_ReturnArray($sPathInfo, $aCorrectValues) { $_SERVER['PATH_INFO'] = $sPathInfo; $oRouter = new Router(array('Default_controller' => 'Ctrl', 'Default_function' => 'indexAction')); $this->assertTrue(array_diff($oRouter->getParams(), $aCorrectValues['params']) === array()); unset($oRouter); unset($_SERVER['PATH_INFO']); }
public function api_users() { $users = $this->Users->readUsers(); $this->set('users', $users); $this->set('paging', Router::getParams()['paging']['User']); $this->set('_serialize', array('users', 'paging')); $this->render('../api_read'); }
/** * __construct * * @access public * @return void */ function __construct() { parent::__construct(); $this->_set(Router::getPaths()); $this->params = Router::getParams(); $this->constructClasses(); $this->Component->initialize($this); $this->_set(array('cacheAction' => false, 'viewPath' => 'errors')); }
/** * */ public function api_items($collection_id) { $items = $this->CollectionItems->getItems($collection_id); $this->set('collectionItems', $items); $this->set('paging', Router::getParams()['paging']['CollectionItem']); $this->set('_serialize', array('collectionItems', 'paging')); $this->render('../api_read'); }
public function __construct($request = null, $response = null) { parent::__construct($request, $response); if ($this->name == 'CakeError') { $this->_set(Router::getPaths()); $this->request->params = Router::getParams(); $this->constructClasses(); $this->startupProcess(); } }
/** * Check wither the routing table has a specific route * @param Router $router * @return bool */ public function has(Router $router) { $found = false; foreach ($this->_routingTable as $routeID => $routeDetails) { if (preg_match("/^" . str_replace('/', '\\/', $routeDetails['_url_']) . "\$/i", $router->getFinalRequestedId()) && in_array($router->getRequest()->getMethod(), $this->_routingTable[$routeID]['_method_'])) { $found = true; break; } } $router->setController($this->_routingTable[$routeID]['_controller_']); $router->setAction($this->_routingTable[$routeID]['_action_']); if (!empty($router->getParams())) { $index = 0; $parameters = array(); $routerFetchedParameters = $router->getParams(); foreach ($this->_routingTable[$routeID]['_params_'] as $parameter) { $parameters[$parameter] = $routerFetchedParameters[$index++]; } $router->setParams($parameters); } return $found; }
public static function init($action = "news") { self::$routerData = Router::getParams(); if (!isset(self::$routerData['clanid'])) { self::$routerData['clanid'] = 1; } if (!isset(self::$routerData['site'])) { self::$routerData['site'] = "news"; } SiteData::siteExists(self::$routerData['clanid']); self::$clanData = SiteData::getSiteData(self::$routerData['clanid']); self::testTemplateType(); }
/** * Constructor * * @access public */ public function __construct() { Croogo::applyHookProperties('Hook.controller_properties'); parent::__construct(); if ($this->name == 'CakeError') { $this->_set(Router::getPaths()); $this->params = Router::getParams(); $this->constructClasses(); $this->Component->initialize($this); $this->beforeFilter(); $this->Component->triggerCallback('startup', $this); } }
/** * Put webmaster tools config on header * * @param CakeEvent $event Represents the transport class of events across the system. * * @return string */ public function putWebmasterToolsConfigOnHeader(CakeEvent $event) { $router = Router::getParams(); if ($router['controller'] == 'posts' && $router['action'] == 'index') { $meta = []; if (Configure::check('HuradSeo')) { $verification = Configure::read('HuradSeo.google_webmaster_verification'); if (Configure::check('HuradSeo.google_webmaster_verification') && !empty($verification)) { $meta[] = $event->subject()->Html->meta(['name' => 'google-site-verification', 'content' => $verification]); } } echo implode("\n", $meta); } }
public static function init() { self::$routerData = Router::getParams(); if (!isset(self::$routerData['clanid'])) { self::$routerData['clanid'] = 1; } if (!isset(self::$routerData['site'])) { self::$routerData['site'] = "news"; } if (self::testIfSiteExists()) { if (!self::testIfSiteClosed()) { self::testTemplateType(); } } }
/** * 引导程序 */ public static function run() { require FRAMEWORK_PATH . 'core/BaseException.class.php'; try { self::appInit(); $cParams = Router::getParams(); //print_r($cParams); //print_r(Router::getRoutes()); Dispather::run($cParams); } catch (BaseException $e) { echo $e->errMsg(); } catch (Exception $e) { echo $e->getMessage(); } }
function __construct($id = false, $table = null, $ds = null) { /* Read the URL to get the controller name */ $url_params = Router::getParams(); if (empty($url_params)) { parent::__construct($id, $table, $ds); return; } /* Activate account database based on the controller name. If admin section use the 'wz' master database */ if ($url_params['controller'] == 'admin' || $url_params['controller'] == 'wzusers' || $url_params['controller'] == 'wzaccounts' || $url_params['controller'] == 'wzsettings') { $this->useDbConfig = 'wz'; } else { $this->useDbConfig = 'wz_accconfig'; } parent::__construct($id, $table, $ds); return; }
/** * */ function __construct($method, $messages) { $params = Router::getParams(); if (($method == 'missingController' || $method == 'missingAction') && file_exists(VIEWS . DS . 'static' . DS . $params['controller'] . ".ctp")) { $this->controller =& new AppController(); $this->controller->_set(Router::getPaths()); $this->controller->params = $params; $this->controller->constructClasses(); $this->controller->beforeFilter(); $this->controller->viewPath = 'static'; $this->controller->render($params['controller']); e($this->controller->output); exit; } parent::__construct($method, $messages); exit; }
/** * Before Save Insert or Update * @param array $options Request Arguments * @return boolean true false * @throws NotFoundException When the view file could not be found * or MissingViewException in debug mode. */ public function beforeSave($options = array()) { //pr($this->data);exit; if (Router::getParams("action") == "admin_skills") { $this->data[$this->alias]['time_created'] = date('Y-m-d H:i:s'); } else { if (isset($this->data[$this->alias]['id']) && $this->data[$this->alias]['id'] == '') { $this->data[$this->alias]['time_created'] = date('Y-m-d H:i:s'); } } $userId = AuthComponent::user('id'); $this->data[$this->alias]['requested_by'] = $userId != "" ? $userId : 0; $userSessionId = AuthComponent::user('user_session_id'); $this->data[$this->alias]['user_session_id'] = $userSessionId != "" ? $userSessionId : 0; $instituteId = AuthComponent::user('institute_id'); $this->data[$this->alias]['institute_id'] = $instituteId != "" ? $instituteId : 0; return parent::beforeSave($options); }
public static function dispatch(Router $router) { // ob_start(); $className = ucfirst($router->getController()) . 'Controller'; $actionName = $router->getAction() . 'Action'; $controllerFile = CONTROLLER_DIR . '/' . $className . '.class.php'; if (file_exists($controllerFile)) { include_once $controllerFile; $app = new $className($router->getParams(), $router->getController()); $app->{$actionName}(); // $output = ob_get_clean(); // echo $output; } else { // throw new Exception('Controller not found. className:['.$className.']'); Log::fatal('Controller not found. className:[%s]', var_export($className, 1)); trigger_error('Controller not found. className:[' . var_export($className, 1) . ']', E_USER_ERROR); } }
function url($url = null, $full = false) { $params = Router::getParams(); if (isset($params['url']['mobile'])) { $params = "?mobile=" . $params['url']['mobile']; } else { $params = ""; } if (is_string($url)) { if (!preg_match('/\\?mobile/', $url)) { return Router::url($url, $full) . $params; } return Router::url($url, $full); } $url = Router::url($url, $full); if (!preg_match('/#.+/', $url)) { return preg_replace('/\\/$/', '', Router::url($url, $full)) . '/' . $params; } return preg_replace('/#/', '/#', $url); }
public function afterSave($created, $options = array()) { //alter table logeventos add entidade_id int(11) $exceptions = array("Logevento", "Session"); $controller = Router::getParams()['controller']; $action = Router::getParams()['action']; $entity = $this->alias; $userId = $this->getUserSession()['Usuario']['id']; if (in_array($entity, $exceptions)) { return false; } //$log = ClassRegistry::init( 'Logevento' ); // $log->createLog( // $userId, // $entity, // $action // $controller.':' . $this->data[$entity]['id'] . ';' . $action. ";link:1", // // ); }
public function initialize(Controller $Controller) { parent::initialize($Controller); $this->Controller = $Controller; if (isset($this->Controller->request->params['named']['mobile'])) { if ($this->Controller->request->params['named']['mobile'] == '-1') { $noMobile = null; } else { $wantsMobile = (bool) $this->Controller->request->params['named']['mobile']; $noMobile = (int) (!$wantsMobile); } $this->Session->write('User.nomobile', $noMobile); } $this->setMobile(); $urlParams = Router::getParams(true); if (!isset($urlParams['named'])) { $urlParams['named'] = array(); } if (!isset($urlParams['pass'])) { $urlParams['pass'] = array(); } $urlParams = am($urlParams, $urlParams['named'], $urlParams['pass']); unset($urlParams['named']); unset($urlParams['pass']); if (isset($urlParams['prefix'])) { unset($urlParams['prefix']); } if ($this->setMobile) { $url = Router::url(am($urlParams, array('mobile' => 0))); $this->Controller->set('desktopUrl', $url); } else { $url = Router::url(am($urlParams, array('mobile' => 1))); $this->Controller->set('mobileUrl', $url); } Configure::write('User.mobile', $this->isMobile); Configure::write('User.setMobile', $this->setMobile); }
/** * Gets URL parameter by name * * @param string $name Parameter name * @param bool $current Current parameter, useful when using requestAction * * @return string|null Parameter value */ public static function getParam($name = 'controller', $current = FALSE) { $params = Router::getParams($current); if (isset($params[$name])) { return $params[$name]; } return NULL; }
function beforeFilter() { /* Read URL to get the controller name */ $url_params = Router::getParams(); /* Load account setting only if the controller is NOT in admin sections */ if ($url_params['controller'] == 'admin' || $url_params['controller'] == 'wzusers' || $url_params['controller'] == 'wzaccounts' || $url_params['controller'] == 'wzsettings') { return; } if (!$this->Auth->user('id')) { return; } /* Load account related settings and entry types */ $account_id = CakeSession::read('ActiveAccount.id'); if (empty($account_id)) { $this->Session->setFlash(__d('webzash', 'Please choose a account.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } /* Write settings */ App::import("Webzash.Model", "Setting"); $Setting = new Setting(); $setting = ''; try { $setting = $Setting->findById(1); } catch (Exception $e) { CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'Settings table is missing. Please check whether this is a valid account database.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } if (!$setting) { CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'Account settings not found. Please check if the database settings are correct.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } /* Check if database version is correct */ if ($setting['Setting']['database_version'] < 5) { CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'You are connecting to a database which belongs to older version of this application. Please check the Wiki in the help section on how to upgrade your database.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } if ($setting['Setting']['database_version'] == 5) { /* If user has admin role then redirect to update page */ if (CakeSession::read('ActiveAccount.account_role') == "admin") { $this->Session->setFlash(__d('webzash', 'You need to update the account database before activating this account.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzaccounts', 'action' => 'update')); } /* If user does not belong to admin role then show message to contact administrator */ CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'You need to update the account database before activating this account. Kindly contact the site administrator to update the account database.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } if ($setting['Setting']['database_version'] > 6) { CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'You are connecting to a database which belongs to newer version of this application. Please upgrade this application before you can connect to the database.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } /* Validate settings */ if (!($setting['Setting']['decimal_places'] == 2 || $setting['Setting']['decimal_places'] == 3)) { CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'Decimal places should be set to 2 or 3 in account settings.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } Configure::write('Account.name', $setting['Setting']['name']); Configure::write('Account.address', $setting['Setting']['address']); Configure::write('Account.email', $setting['Setting']['email']); Configure::write('Account.currency_symbol', $setting['Setting']['currency_symbol']); Configure::write('Account.currency_format', $setting['Setting']['currency_format']); Configure::write('Account.decimal_places', $setting['Setting']['decimal_places']); $dateFormat = explode('|', $setting['Setting']['date_format']); Configure::write('Account.dateformatPHP', $dateFormat[0]); Configure::write('Account.dateformatJS', $dateFormat[1]); Configure::write('Account.startdate', $setting['Setting']['fy_start']); Configure::write('Account.enddate', $setting['Setting']['fy_end']); Configure::write('Account.locked', $setting['Setting']['account_locked']); Configure::write('Account.email_use_default', $setting['Setting']['email_use_default']); Configure::write('Account.CurrentDatabaseVersion', $setting['Setting']['database_version']); /* Write entry types */ App::import("Webzash.Model", "Entrytype"); $Entrytype = new Entrytype(); $rawentrytypes = ''; try { $rawentrytypes = $Entrytype->find('all'); } catch (Exception $e) { CakeSession::delete('ActiveAccount.id'); CakeSession::delete('ActiveAccount.account_role'); $this->Session->setFlash(__d('webzash', 'Entry types table is missing. Please check whether this is a valid account database.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account')); } $entrytypes = array(); foreach ($rawentrytypes as $entrytype) { $entrytypes[$entrytype['Entrytype']['id']] = array('prefix' => $entrytype['Entrytype']['prefix'], 'suffix' => $entrytype['Entrytype']['suffix'], 'zero_padding' => $entrytype['Entrytype']['zero_padding'], 'label' => $entrytype['Entrytype']['label'], 'name' => $entrytype['Entrytype']['name']); } Configure::write('Account.ET', $entrytypes); }
<?php //spl_autoload_register(); require '../Core/Router.php'; $router = new Router(); $router->add('', ['controller' => 'Home', 'action' => 'index']); $router->add('posts', ['controller' => 'Posts', 'action' => 'index']); //$router->add('posts/new', ['controller' => 'Posts', 'action' => 'new']); $router->add('{controller}/{action}'); $router->add('admin/{controller}/{action}'); $url = $_SERVER['QUERY_STRING']; if ($router->match($url)) { echo '<pre>'; var_dump($router->getRoutes()); var_dump($router->getParams()); echo '</pre>'; } else { echo 'no routes found for URL ' . $url; }
/** * testGetParams * * @return void */ public function testGetParams() { $paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot'); $params = array('param1' => '1', 'param2' => '2'); Router::setRequestInfo(array($params, $paths)); $expected = array('plugin' => null, 'controller' => false, 'action' => false, 'param1' => '1', 'param2' => '2'); $this->assertEquals(Router::getParams(), $expected); $this->assertEquals(Router::getParam('controller'), false); $this->assertEquals(Router::getParam('param1'), '1'); $this->assertEquals(Router::getParam('param2'), '2'); Router::reload(); $params = array('controller' => 'pages', 'action' => 'display'); Router::setRequestInfo(array($params, $paths)); $expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEquals(Router::getParams(), $expected); $this->assertEquals(Router::getParams(true), $expected); }
/** * Gets URL parameter by name * * @param string $name Parameter name * @param boolean $current Current parameter, useful when using requestAction * @return string Parameter value * @access public * @static */ function getParam($name = 'controller', $current = false) { $params = Router::getParams($current); if (isset($params[$name])) { return $params[$name]; } return null; }
function checkRoute($route = null) { list($controller, $action) = explode('#', $route); $params = Router::getParams(); return $params['controller'] == $controller && $params['action'] == $action; }