ZF2-动态基本路线

ZF2- Dynamic base route

我正在尝试在 ZF2 项目中创建动态路线。它将类似于 "domain.com/companyurl/products"。公司 url 充满活力。我做到了:

'company' => array(
     'type' => 'Segment',
     'options' => array(
         'route' => '[/:company]',
         'defaults' => array(
             'controller' => 'IndexController',
             'action'     => 'index',
          ),
      ),
      'may_terminate' => true,
      'child_routes' => array(
          ...
      ),

 ),

但我总是必须在路由中传递公司参数。

$this->url('company/products', array('company' => 'companyurl'));

有没有办法在运行时指定一个基本路由,比如一个基本url,然后所有的路由都会跟随它?像这样:

$this->url('products');

$this->url('company/products');

在这两种情况下,我都已经指定了基本路由值。

希望你明白我的意思。谢谢

您可以在 URL 助手中使用一个 $reuseRouteParams 选项:

$this->url($name, $params, $options,$reuseMatchedParameters);

如果将此设置为 true,它将重复使用 companyUrl 的先前路由匹配值。

您可以在文档中阅读更多相关信息 here