2013-01-08 88 views
0

在Zend Framework 2应用程序中,我有两种语言'nl'(默认)和'en'。请求的URL为 'NL' 是这样的:ZF2中的默认语言路由

/controller/action 

和 '恩',如:

/en/controller/action 

首先,我要路由/重写默认语言设置为:

/NL /控制器/动作

以便能够随后使用段路线等:

[:lang/[:controller/[:action]]] 

我试图与下面的正则表达式的路线(与前面负的样子)

'lang' => array(
    'type' => 'Zend\Mvc\Router\Http\Regex', 
    'options' => array(
     'regex' => '/(?!en)(.*)', 
     'spec' => '/nl$2', 
    ), 
), 

(这条路线不应该映射到控制器/动作,但应该只重写URL到一个新的)

但我得到:

Page not found. 

The requested controller could not be mapped to an existing controller class. 

什么是正确运作的路线?或者使用Web服务器重写更好?

回答

0

一个正则表达式的路线是没有必要的,下面的工作也是如此。语言段是可选的。在我的应用程序中,它只能是'en',如果省略,默认值为'nl':

'router' => array(
     'routes' => array(
      'home' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         'controller' => 'Application\Controller\Index', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'language' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '[:lang/]', 
          'constraints' => array(
           'lang'  => 'en', 
          ), 
          'defaults' => array(
           'lang' => 'nl', 
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
1

的路线应该是

/[:lang/[:controller/[:action]]] 
+0

这就像我在我的代码中,我没有使用复制/粘贴。然而问题出在了正则表达式中。我编辑了我的问题。 – tihe