Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 public function testAssembleWithMappedVariableAndNumericKey()
 {
     $route = new Zend_Controller_Router_Route_Regex('users/(.+)', null, array(1 => 'username'), 'users/%s');
     $values = $route->match('users/martel');
     $url = $route->assemble(array(1 => 'vicki'));
     $this->assertSame('users/vicki', $url);
 }
Example #4
0
    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);
    }
Example #5
0
 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;
 }
Example #6
0
 /**
  * @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)));
 }
Example #7
0
 public function testAssembleZF1332()
 {
     $route = new Zend_Controller_Router_Route_Regex('(.+)\\.([0-9]+)-([0-9]+)\\.html', array('module' => 'default', 'controller' => 'content.item', 'action' => 'forward'), array(1 => 'name', 2 => 'id', 3 => 'class'), '%s.%s-%s.html');
     $route->match('uml-explained-composition.72-3.html');
     $url = $route->assemble();
     $this->assertSame('uml-explained-composition.72-3.html', $url);
     $url = $route->assemble(array('name' => 'post_name', 'id' => '12', 'class' => 5));
     $this->assertSame('post_name.12-5.html', $url);
 }
Example #8
0
 /**
  * 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;
             }
         }
     }
 }