【问题标题】:zend router with arbitrary paths具有任意路径的zend路由器
【发布时间】:2011-12-18 11:50:15
【问题描述】:

所以我要设置路由器

  protected function _initRoutes(){
      $front = Zend_Controller_Front::getInstance();
      $router = $front->getRouter();
      $routerInfo =  array('action' => 'theaction',
                           'controller' => 'thecontroller',);
       $route = new Zend_Controller_Router_Route(
                         'some/path',
                         $routerInfo
       );
       $router->addRoute('some/path', $route);

      return $router;
  }

所以控制器“一些”和动作“路径”实际上并不存在。相反,当用户转到 /some/path 时,它应该重定向到 'theaction/thecontroller' ......

我的问题是...如何设置它以便我可以在 /some/path 之后接受任意数量的参数...例如,我希望 /some/path/other/param 也重定向到同一个页面...所以只要路径的第一段是/some/path,不管后面是什么,我都希望它们都重定向到同一个控制器和动作

我知道你可以这样做 /some/path/*/*....但只有在 /some/path 之后只有 2 个其他路径项时才有效.....我希望它适用于任意数量的参数....so /some/path/param1/value1/param2/value2/param3/value3 也应该仍然有效,就好像用户输入了控制器/动作/参数1/值1/参数2/值2/参数3/值3 ...

【问题讨论】:

    标签: php zend-framework url redirect


    【解决方案1】:

    您只需使用单个星号,例如

    $route = new Zend_Controller_Router_Route(
        'some/path/*',
        array(
            'action'     => 'theaction',
            'controller' => 'thecontroller',
            'module'     => 'default'
        )
    );
    
    // can't say for sure but a slash in the route name is probably a bad idea
    // try a hyphen instead
    $router->addRoute('some-path', $route);
    

    在此处查看第三个示例 - http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard

    仅供参考,不要在 Bootstrap 方法中获取 FrontController 那样的资源。改用这个...

    $this->bootstrap('FrontController');
    $front = $this->getResource('FrontController');
    

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      • 1970-01-01
      相关资源
      最近更新 更多