/** * Matches a user submitted path with a previously defined route. * Assigns and returns an array of defaults on a successful match. * @param string $path Path used to match against this routing map * @param boolean $partial * @return array|false An array of assigned values or a false on a mismatch * @author LamTX */ public function match($path, $partial = false) { $return = parent::match($path, $partial); switch ($return['cate_code']) { case 'photo': $return['controller'] = 'photo'; $return['action'] = 'index'; break; case 'video': $return['controller'] = 'video'; $return['action'] = 'index'; break; case '32-doi': $return['controller'] = 'team'; $return['action'] = 'index'; break; case 'du-doan': $return['controller'] = 'team'; $return['action'] = 'dudoan'; break; default: break; } return $return; }
/** * Matches a user submitted path with a previously defined route. * Assigns and returns an array of defaults on a successful match. * @param string $path Path used to match against this routing map * @param boolean $partial * @return array|false An array of assigned values or a false on a mismatch * @author LamTX */ public function match($path, $partial = false) { $return = parent::match($path, $partial); if ($return) { if ($return['action'] == 'video') { $return['controller'] = 'video'; $return['action'] = 'index'; } elseif ($return['action'] == 'tin-tuc') { $return['action'] = 'index'; } } return $return; }
public function testAssembleWithMappedVariableWithoutMatch() { $route = new Zend_Controller_Router_Route_Regex('users/(.+)', null, array(1 => 'username'), 'users/%s'); $url = $route->assemble(array('username' => 'vicki')); $this->assertSame('users/vicki', $url); }
public function testVariableUnsettingRegex() { $foo = new Zend_Controller_Router_Route_Regex('([^/]+)', array(), array(1 => 'foo'), '%s'); $bar = new Zend_Controller_Router_Route_Module(array('controller' => 'ctrl', 'action' => 'act')); $chain = $foo->chain($bar); $path = $chain->assemble(array('foo' => 'bar', 'baz' => 'bat')); $this->assertEquals('bar/ctrl/act/baz/bat', $path); }
public function testAssembleZF2301() { $route = new Zend_Controller_Router_Route_Regex( "itemlist(?:/(\d+))?", array('page' => 1), // Defaults array(1 => 'page'), // Parameter map 'itemlist/%d' ); $values = $route->match('/itemlist/2'); $this->assertEquals(array('page' => 2), $values); $url = $route->assemble(); $this->assertEquals('itemlist/2', $url); $url = $route->assemble(array('page' => 2)); $this->assertEquals('itemlist/2', $url); }
function match($path) { $return = parent::match($path); if (!$return) { return $this->_defaults; } $this->_values = $return; // on ignore les valeur non définie. foreach ($this->_values as $k => $v) { if (!$v) { unset($this->_values[$k]); } } // lecture des paramètre jocker. Stockage dans $this->_params; if (array_key_exists('#', $this->_values)) { preg_match_all("`([[:alpha:]]+/[^/]+)`", $this->_values['#'], $res); foreach ($res[1] as $r) { list($k, $v) = explode('/', $r); // don't overwrite existing fields if (!isset($return[$k])) { $this->_params[$k] = $v; } } unset($this->_values['#']); } $return = $this->_values + $this->_params + $this->_defaults; return $return; }
/** * Allow using <lang>1</lang> instead of invalid <1>lang</1> for xml router * config. * * <zend-config> * <routes> * <page> * <type>Zend_Controller_Router_Route_Regex</type> * <route>([a-z]{2})/page/(.*)</route> * <defaults> * <controller>index</controller> * <action>showpage</action> * </defaults> * <map> * <lang>1</lang> * <title>2</title> * </map> * <reverse>%s/page/%s</reverse> * </page> * </routes> * </zend-config> * * * @group ZF-7658 */ public function testAssembleWithFlippedMappedVariables() { $route = new Zend_Controller_Router_Route_Regex('([a-z]{2})/page/(.*)', array('controller' => 'index', 'action' => 'showpage'), array('lang' => 1, 'title' => 2), '%s/page/%s'); $url = $route->assemble(array('lang' => 'fi', 'title' => 'Suomi'), true, true); $this->assertEquals($url, 'fi/page/Suomi'); }
public function testGetInstance() { require_once 'Zend/Config.php'; $routeConf = array('route' => 'forum/(\\d+)', 'reverse' => 'forum/%d', 'defaults' => array('controller' => 'ctrl')); /* numeric Zend_Config indexes don't work at the moment 'map' => array( '1' => 'forum_id' ) */ $config = new Zend_Config($routeConf); $route = Zend_Controller_Router_Route_Regex::getInstance($config); $this->assertType('Zend_Controller_Router_Route_Regex', $route); $values = $route->match('forum/1'); $this->assertSame('ctrl', $values['controller']); }
/** * @issue ZF-2301 */ public function testAssemblyOfRouteWithMergedMatchedParts() { $route = new Zend_Controller_Router_Route_Regex('itemlist(?:/(\\d+))?', array('page' => 1), array(1 => 'page'), 'itemlist/%d'); // make sure defaults work $this->assertEquals(array('page' => 1), $route->match('/itemlist/')); // make sure default assembly work $this->assertEquals('itemlist/1', $route->assemble()); // make sure the route is parsed correctly $this->assertEquals(array('page' => 2), $route->match('/itemlist/2')); // check to make sure that the default assembly will return with default 1 (previously defined) $this->assertEquals('itemlist/2', $route->assemble()); // check to make sure that the assembly will return with provided page=3 in the correct place $this->assertEquals('itemlist/3', $route->assemble(array('page' => 3))); // check to make sure that the assembly can reset a single parameter $this->assertEquals('itemlist/1', $route->assemble(array('page' => null))); }
/** * Loading the modules in front controller. */ public static function initFrontController() { $frontController = \Zend_Controller_Front::getInstance(); $frontController->setDefaultModule(self::$module); $directoryiterator = new \DirectoryIterator(self::$applicationPath); $request = new \Zend_Controller_Request_Http(); foreach ($directoryiterator as $directory) { $name = $directory->getBaseName(); if ($directory->isDir() and substr($name, 0, 1) != '.' and $name != 'configs') { //Adding the controllers directory. $controllers = sprintf('%s/%s/controllers', self::$applicationPath, $name); $frontController->addControllerDirectory($controllers, $name); //Setting the current module name. $route = new \Zend_Controller_Router_Route_Regex(sprintf('/%s/*', $name)); if (is_array($route->match($request->getRequestUri(), true))) { self::$module = $name; } } } }