当前位置: 首页>>代码示例>>PHP>>正文


PHP Router::currentRoute方法代码示例

本文整理汇总了PHP中Router::currentRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::currentRoute方法的具体用法?PHP Router::currentRoute怎么用?PHP Router::currentRoute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Router的用法示例。


在下文中一共展示了Router::currentRoute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: error500

 public function error500($error)
 {
     if (Router::currentRoute()->defaults['plugin'] == 'api') {
         $this->controller->viewClass = 'Json';
     }
     parent::error500($error);
 }
开发者ID:port80labs,项目名称:Boxmeup,代码行数:7,代码来源:ApiExceptionRenderer.php

示例2: testAssignsCurrentRoute

 public function testAssignsCurrentRoute()
 {
     $route = Router::get('/apath', function () {
     });
     $this->assertNull(Router::currentRoute());
     Router::run('GET', 'localboat.dev', '/apath');
     $this->assertNotNull(Router::currentRoute());
 }
开发者ID:kiasaki,项目名称:vexillum,代码行数:8,代码来源:RouterTest.php

示例3: initialize

 /**
  * Controllers initialize function.
  */
 public function initialize($Controller)
 {
     parent::initialize($Controller);
     $this->Controller = $Controller;
     Configure::write('CORE.current_route', Router::currentRoute());
     $this->__registerPlugins();
     $this->__paginationRecall();
     if (Configure::read('Website.force_www')) {
         $this->forceWwwUrl();
     }
 }
开发者ID:nani8124,项目名称:infinitas,代码行数:14,代码来源:InfinitasComponent.php

示例4: beforeRender

 /**
  * beforeRender callback - grabs request params
  *
  * @param Controller $controller
  * @return array
  */
 public function beforeRender(Controller $controller)
 {
     $out = array();
     $out['params'] = $controller->request->params;
     $out['url'] = $controller->request->url;
     $out['query'] = $controller->request->query;
     $out['data'] = $controller->request->data;
     if (isset($controller->Cookie)) {
         $out['cookie'] = $controller->Cookie->read();
     }
     $out['get'] = $_GET;
     $out['currentRoute'] = Router::currentRoute();
     return $out;
 }
开发者ID:4Queen,项目名称:php-buildpack,代码行数:20,代码来源:RequestPanel.php

示例5: loadModules

 /**
  * Module Loader.
  *
  * This is used to load modules. it generates a wrapper div with the class
  * set as the module name for easy styleing, and will create a header if set
  * in the backend.
  *
  * @params string $position this is the possition that is to be loaded, can be anything from the database
  * @params bool $admin if true its a admin module that should be loaded.
  */
 function loadModules($position = null, $admin = false)
 {
     if (!$position) {
         $this->errors[] = 'No position selected to load modules';
         return false;
     }
     $modules = ClassRegistry::init('Management.Module')->getModules($position, $admin);
     $out = '<div class="modules ' . $position . '">';
     $currentRoute = Router::currentRoute();
     foreach ($modules as $module) {
         if ($module['Theme']['name'] != '' && $module['Theme']['name'] != $this->theme) {
             //skip modules that are not for the current theme
             continue;
         }
         $moduleOut = '<div class="module ' . $module['Module']['module'] . '">';
         if ($module['Module']['show_heading']) {
             $moduleOut .= '<h2>' . __($module['Module']['name'], true) . '</h2>';
         }
         if (!empty($module['Module']['module'])) {
             $View = ClassRegistry::getObject('View');
             $path = 'modules/';
             if ($admin) {
                 $path .= 'admin/';
             }
             $moduleOut .= $View->element($path . $module['Module']['module'], array('config' => $this->_moduleConfig($module['Module'])), true);
         } else {
             if (!empty($module['Module']['content'])) {
                 $moduleOut .= $module['Module']['content'];
             }
         }
         $moduleOut .= '</div>';
         if (!empty($module['Route']) && is_object($currentRoute)) {
             foreach ($module['Route'] as $route) {
                 if ($route['url'] == $currentRoute->template) {
                     $out .= $moduleOut;
                 }
             }
         } else {
             if (empty($module['Route'])) {
                 $out .= $moduleOut;
             }
         }
     }
     $out .= '</div>';
     return $out;
 }
开发者ID:rchavik,项目名称:infinitas,代码行数:56,代码来源:infinitas.php

示例6: testCurentRoute

 /**
  * testCurentRoute
  *
  * This test needs some improvement and actual requestAction() usage
  * 
  * @return void
  * @access public
  */
 function testCurentRoute()
 {
     $url = array('controller' => 'pages', 'action' => 'display', 'government');
     Router::connect('/government', $url);
     Router::parse('/government');
     $route = Router::currentRoute();
     $this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]);
 }
开发者ID:laiello,项目名称:myopensources,代码行数:16,代码来源:router.test.php

示例7: _testAction

 /**
  * Lets you do functional tests of a controller action.
  *
  * ### Options:
  *
  * - `data` Will be used as the request data. If the `method` is GET,
  *   data will be used a GET params. If the `method` is POST, it will be used
  *   as POST data. By setting `$options['data']` to a string, you can simulate XML or JSON
  *   payloads to your controllers allowing you to test REST webservices.
  * - `method` POST or GET. Defaults to POST.
  * - `return` Specify the return type you want. Choose from:
  *     - `vars` Get the set view variables.
  *     - `view` Get the rendered view, without a layout.
  *     - `contents` Get the rendered view including the layout.
  *     - `result` Get the return value of the controller action. Useful
  *       for testing requestAction methods.
  *
  * @param string $url The url to test
  * @param array $options See options
  * @return mixed
  */
 protected function _testAction($url = '', $options = array())
 {
     $this->vars = $this->result = $this->view = $this->contents = $this->headers = null;
     $options = array_merge(array('data' => array(), 'method' => 'POST', 'return' => 'result'), $options);
     $restore = array('get' => $_GET, 'post' => $_POST);
     $_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
     if (is_array($options['data'])) {
         if (strtoupper($options['method']) === 'GET') {
             $_GET = $options['data'];
             $_POST = array();
         } else {
             $_POST = $options['data'];
             $_GET = array();
         }
     }
     $request = $this->getMock('CakeRequest', array('_readInput'), array($url));
     if (is_string($options['data'])) {
         $request->expects($this->any())->method('_readInput')->will($this->returnValue($options['data']));
     }
     $Dispatch = new ControllerTestDispatcher();
     foreach (Router::$routes as $route) {
         if ($route instanceof RedirectRoute) {
             $route->response = $this->getMock('CakeResponse', array('send'));
         }
     }
     $Dispatch->loadRoutes = $this->loadRoutes;
     $Dispatch->parseParams(new CakeEvent('ControllerTestCase', $Dispatch, array('request' => $request)));
     if (!isset($request->params['controller']) && Router::currentRoute()) {
         $this->headers = Router::currentRoute()->response->header();
         return;
     }
     if ($this->_dirtyController) {
         $this->controller = null;
     }
     $plugin = empty($request->params['plugin']) ? '' : Inflector::camelize($request->params['plugin']) . '.';
     if ($this->controller === null && $this->autoMock) {
         $this->generate($plugin . Inflector::camelize($request->params['controller']));
     }
     $params = array();
     if ($options['return'] === 'result') {
         $params['return'] = 1;
         $params['bare'] = 1;
         $params['requested'] = 1;
     }
     $Dispatch->testController = $this->controller;
     $Dispatch->response = $this->getMock('CakeResponse', array('send'));
     $this->result = $Dispatch->dispatch($request, $Dispatch->response, $params);
     $this->controller = $Dispatch->testController;
     $this->vars = $this->controller->viewVars;
     $this->contents = $this->controller->response->body();
     if (isset($this->controller->View)) {
         $this->view = $this->controller->View->fetch('__view_no_layout__');
     }
     $this->_dirtyController = true;
     $this->headers = $Dispatch->response->header();
     $_GET = $restore['get'];
     $_POST = $restore['post'];
     return $this->{$options['return']};
 }
开发者ID:jgera,项目名称:orangescrum,代码行数:80,代码来源:ControllerTestCase.php

示例8: _testAction

 /**
  * Tests a controller action.
  *
  * ### Options:
  *
  * - `data` POST or GET data to pass
  * - `method` POST or GET
  *
  * @param string $url The url to test
  * @param array $options See options
  */
 private function _testAction($url = '', $options = array())
 {
     $this->vars = $this->result = $this->view = $this->contents = $this->headers = null;
     $options = array_merge(array('data' => array(), 'method' => 'POST', 'return' => 'result'), $options);
     if (strtoupper($options['method']) == 'GET') {
         $_GET = $options['data'];
         $_POST = array();
     } else {
         $_POST = array('data' => $options['data']);
         $_GET = array();
     }
     $request = new CakeRequest($url);
     $Dispatch = new ControllerTestDispatcher();
     foreach (Router::$routes as $route) {
         if (is_a($route, 'RedirectRoute')) {
             $route->response = $this->getMock('CakeResponse', array('send'));
         }
     }
     $Dispatch->loadRoutes = $this->loadRoutes;
     $request = $Dispatch->parseParams($request);
     if (!isset($request->params['controller'])) {
         $this->headers = Router::currentRoute()->response->header();
         return;
     }
     if ($this->controller !== null && Inflector::camelize($request->params['controller']) !== $this->controller->name) {
         $this->controller = null;
     }
     if ($this->controller === null && $this->autoMock) {
         $this->generate(Inflector::camelize($request->params['controller']));
     }
     $params = array();
     if ($options['return'] == 'result') {
         $params['return'] = 1;
         $params['bare'] = 1;
         $params['requested'] = 1;
     }
     $Dispatch->testController = $this->controller;
     $Dispatch->response = $this->getMock('CakeResponse', array('send'));
     $this->result = $Dispatch->dispatch($request, $params);
     $this->controller = $Dispatch->testController;
     if ($options['return'] != 'result') {
         $this->vars = $this->controller->View->viewVars;
         $this->view = $this->controller->View->_viewNoLayout;
         $this->contents = $this->controller->response->body();
     }
     $this->headers = $Dispatch->response->header();
     return $this->{$options['return']};
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:59,代码来源:controller_test_case.php

示例9: beforeRender

 /**
  * beforeRender callback - grabs request params
  *
  * @return array
  **/
 function beforeRender(&$controller)
 {
     $out = array();
     $out['params'] = $controller->params;
     if (isset($controller->Cookie)) {
         $out['cookie'] = $controller->Cookie->read();
     }
     $out['get'] = $_GET;
     $out['currentRoute'] = Router::currentRoute();
     return $out;
 }
开发者ID:TomMaher,项目名称:umambo,代码行数:16,代码来源:toolbar.php

示例10: beforeRender

 public function beforeRender(Controller $Controller)
 {
     parent::beforeRender($Controller);
     if ($Controller->layout == 'ajax') {
         return;
     }
     if (!empty($Controller->viewVars['error']) && $Controller->viewVars['error'] instanceof Exception) {
         $error = $Controller->viewVars['error'];
         unset($Controller->viewVars['error']);
     }
     $layout = array_values($Controller->viewVars);
     $theme = current(Set::extract('/Layout/theme_id', $layout));
     $layout = current(Set::extract('/Layout/layout', $layout));
     if (!empty($error)) {
         $Controller->viewVars['error'] = $error;
         $layout = 'error';
     }
     if ($layout) {
         Configure::write('Themes.default_layout', $layout);
     }
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeStart');
     if (isset($event['setupThemeStart'][$Controller->plugin])) {
         if (is_string($event['setupThemeStart'][$Controller->plugin])) {
             $Controller->theme = $event['setupThemeStart'][$Controller->plugin];
             return true;
         } else {
             if ($event['setupThemeStart'][$Controller->plugin] === false) {
                 return false;
             }
         }
     }
     $Controller->layout = Configure::read('Themes.default_layout');
     $theme = Cache::read('currentTheme');
     if ($theme === false) {
         $theme = ClassRegistry::init('Themes.Theme')->getCurrentTheme();
     }
     if (!empty($theme['Theme']['default_layout'])) {
         $Controller->layout = $theme['Theme']['default_layout'];
     }
     if (isset($Controller->request->params['admin']) && $Controller->request->params['admin']) {
         $Controller->layout = Configure::read('Themes.default_layout_admin');
     }
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeLayout', array('layout' => $Controller->layout, 'params' => $Controller->request->params));
     if (isset($event['setupThemeLayout'][$Controller->plugin]) && is_string($event['setupThemeLayout'][$Controller->plugin])) {
         $Controller->layout = $event['setupThemeLayout'][$Controller->plugin];
     }
     if (!isset($theme['Theme']['name'])) {
         $theme['Theme'] = array('name' => null);
     } else {
         $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeSelector', array('theme' => $theme['Theme'], 'params' => $Controller->request->params));
         if (isset($event['setupThemeSelector'][$Controller->plugin])) {
             if (is_array($event['setupThemeSelector'][$Controller->plugin])) {
                 $theme['Theme'] = $event['setupThemeSelector'][$Controller->plugin];
                 if (!isset($theme['Theme']['name'])) {
                     $this->cakeError('eventError', array('message' => 'The theme is invalid.', 'event' => $event));
                 }
             }
         }
     }
     $Controller->theme = $theme['Theme']['name'];
     Configure::write('Theme', $theme['Theme']);
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeRoutes', array('params' => $Controller->request->params));
     if (isset($event['setupThemeRoutes'][$Controller->plugin]) && !$event['setupThemeRoutes'][$Controller->plugin]) {
         return false;
     }
     if (empty($routes)) {
         $routes = Classregistry::init('Routes.Route')->getRoutes();
     }
     $currentRoute = Router::currentRoute(Configure::read('CORE.current_route'));
     if (!empty($routes) && is_object($currentRoute)) {
         foreach ($routes as $route) {
             if ($route['Route']['url'] == $currentRoute->template) {
                 if (!empty($route['Route']['theme'])) {
                     $Controller->theme = $route['Route']['theme'];
                 }
                 if (!empty($route['Route']['layout'])) {
                     $Controller->layout = $route['Route']['layout'];
                 }
             }
         }
     }
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeEnd', array('theme' => $Controller->theme, 'params' => $Controller->request->params));
     if (isset($event['setupThemeEnd'][$Controller->plugin])) {
         if (is_string($event['setupThemeEnd'][$Controller->plugin])) {
             $Controller->theme = $event['setupThemeEnd'][$Controller->plugin];
         }
     }
     return true;
 }
开发者ID:nani8124,项目名称:infinitas,代码行数:89,代码来源:ThemesComponent.php

示例11: isActive

 /**
  * Checks if a given url is currently active
  * @param mixed $url The url to check, can be and valid router string or array
  * @return boolean Returns true if the passed url is active
  */
 function isActive($url)
 {
     $currentRoute = Router::currentRoute();
     $url = Router::url($url);
     if ($currentRoute[0] == $url) {
         return true;
     }
     return false;
 }
开发者ID:alegz,项目名称:pagebakery.org-cms,代码行数:14,代码来源:navigation.php

示例12: setupTheme

 /**
  * Setup the theme for the site
  *
  * Gets the current theme set in db and sets if up
  */
 function setupTheme()
 {
     $event = $this->Controller->Event->trigger($this->Controller->plugin . '.setupThemeStart');
     if (isset($event['setupThemeStart'][$this->Controller->plugin])) {
         if (is_string($event['setupThemeStart'][$this->Controller->plugin])) {
             $this->Controller->theme = $event['setupThemeStart'][$this->Controller->plugin];
             return true;
         } else {
             if ($event['setupThemeStart'][$this->Controller->plugin] === false) {
                 return false;
             }
         }
     }
     $this->Controller->layout = 'front';
     if (isset($this->Controller->params['admin']) && $this->Controller->params['admin']) {
         $this->Controller->layout = 'admin';
     }
     $event = $this->Controller->Event->trigger($this->Controller->plugin . '.setupThemeLayout', array('layout' => $this->Controller->layout, 'params' => $this->Controller->params));
     if (isset($event['setupThemeLayout'][$this->Controller->plugin])) {
         if (is_string($event['setupThemeLayout'][$this->Controller->plugin])) {
             $this->Controller->layout = $event['setupThemeLayout'][$this->Controller->plugin];
         }
     }
     if (!($theme = Cache::read('currentTheme'))) {
         $theme = ClassRegistry::init('Management.Theme')->getCurrentTheme();
     }
     if (!isset($theme['Theme']['name'])) {
         $theme['Theme'] = array();
     } else {
         $event = $this->Controller->Event->trigger($this->Controller->plugin . '.setupThemeSelector', array('theme' => $theme['Theme'], 'params' => $this->Controller->params));
         if (isset($event['setupThemeSelector'][$this->Controller->plugin])) {
             if (is_array($event['setupThemeSelector'][$this->Controller->plugin])) {
                 $theme['Theme'] = $event['setupThemeSelector'][$this->Controller->plugin];
                 if (!isset($theme['Theme']['name'])) {
                     $this->cakeError('eventError', array('message' => 'The theme is invalid.', 'event' => $event));
                 }
             }
         }
     }
     $this->Controller->theme = $theme['Theme']['name'];
     Configure::write('Theme', $theme['Theme']);
     $event = $this->Controller->Event->trigger($this->Controller->plugin . '.setupThemeRoutes', array('params' => $this->Controller->params));
     if (isset($event['setupThemeRoutes'][$this->Controller->plugin]) && !$event['setupThemeRoutes'][$this->Controller->plugin]) {
         return false;
     }
     $routes = Cache::read('routes', 'core');
     if (empty($routes)) {
         $routes = Classregistry::init('Management.Route')->getRoutes();
     }
     $currentRoute = Router::currentRoute();
     if (!empty($routes) && is_object($currentRoute)) {
         foreach ($routes as $route) {
             if ($route['Route']['url'] == $currentRoute->template && !empty($route['Route']['theme'])) {
                 $this->Controller->theme = $route['Route']['theme'];
             }
         }
     }
     $event = $this->Controller->Event->trigger($this->Controller->plugin . '.setupThemeEnd', array('theme' => $this->Controller->theme, 'params' => $this->Controller->params));
     if (isset($event['setupThemeEnd'][$this->Controller->plugin])) {
         if (is_string($event['setupThemeEnd'][$this->Controller->plugin])) {
             $this->Controller->theme = $event['setupThemeEnd'][$this->Controller->plugin];
         }
     }
 }
开发者ID:rchavik,项目名称:infinitas,代码行数:69,代码来源:infinitas.php

示例13: __extractCustomRoutesElements

 /**
  * Extract from $params custom routes element, defined such as
  * '/:controller/:year/:month/:day', which are not present inside passedArgs
  *
  * @param array $params
  * @access private
  */
 private function __extractCustomRoutesElements($params = array())
 {
     $route = Router::currentRoute();
     if (!$route) {
         return array();
     }
     $customElements = array_intersect_key($params, array_flip($route->keys));
     return $customElements;
 }
开发者ID:hiromi2424,项目名称:mi,代码行数:16,代码来源:menu.php


注:本文中的Router::currentRoute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。