2013-01-08 87 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