public function test_getInstance_fromINIConfig() { $config = new INIConfig(__DIR__ . '/../Controller/_files/routes.ini', 'testing'); $router = new RewriteRouter(); $router->addConfig($config, 'routes'); $route = $router->getRoute('rest'); $this->assertType('Zend\\Rest\\Route', $route); $this->assertEquals('object', $route->getDefault('controller')); $request = $this->_buildRequest('GET', '/mod/project'); $values = $this->_invokeRouteMatch($request, array(), $route); $this->assertEquals('mod', $values['module']); $this->assertEquals('project', $values['controller']); $this->assertEquals('index', $values['action']); $request = $this->_buildRequest('POST', '/mod/user'); $values = $this->_invokeRouteMatch($request, array(), $route); $this->assertEquals('mod', $values['module']); $this->assertEquals('user', $values['controller']); $this->assertEquals('post', $values['action']); $request = $this->_buildRequest('GET', '/other'); $values = $this->_invokeRouteMatch($request, array(), $route); $this->assertFalse($values); }
/** * Retrieve router object * * @return \Zend\Controller\Router\Rewrite */ public function getRouter() { if (null === $this->_router) { $bootstrap = $this->getBootstrap(); $bootstrap->bootstrap('frontcontroller'); $this->_router = $bootstrap->getContainer()->frontcontroller->getRouter(); $options = $this->getOptions(); if (!isset($options['routes'])) { $options['routes'] = array(); } if (isset($options['chainNameSeparator'])) { $this->_router->setChainNameSeparator($options['chainNameSeparator']); } if (isset($options['useRequestParametersAsGlobal'])) { $this->_router->useRequestParametersAsGlobal($options['useRequestParametersAsGlobal']); } $this->_router->addConfig(new \Zend\Config\Config($options['routes'])); } return $this->_router; }
public function _initRoutes() { $this->bootstrap('FrontController'); $front = Front::getInstance(); $router = new RouterRewrite(); $router->addRoute('game-view', new Route('game/view/:game_id/:game_name', array('module' => 'default', 'controller' => 'game', 'action' => 'view'))); $front->setRouter($router); }
protected function _getRouter() { $router = new Router\Rewrite(); $front = Controller\Front::getInstance(); $front->resetInstance(); $front->setRequest(new Request()); $router->setFrontController($front); return $router; }