2014-09-03 124 views
-1

我想添加crm作爲CRM模塊的前綴。帶前綴的ZF2路由在默認情況下不工作

這是路由器節我module.config.php

'router' => array(
     'routes' => array(   
      'calendar' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '/crm/calendar[/:action][/:id]', 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'  => '[0-9]+', 
        ), 
        'defaults' => array(
         'controller' => 'Crm\Controller\Calendar', 
         'action'  => 'index', 
        ), 
       ), 
      ), 

當我使用test.dev/crm/calendar/index工作正常。但它不適用於test.dev/crm/calendar。我找不到任何問題。我使用'route' => '/calendar[/:action][/:id]',我可以使用test.dev/calendar。但我需要使用前綴。我該怎麼做?

+3

您的路線配置是正確的,它必須是別的。爲什麼它'不工作'?你會得到什麼錯誤? – AlexP 2014-09-03 08:15:30

+0

配置無誤。因爲它在某個網址中工作。當我使用/ crm/calender時,它不會重定向到相關操作。 – 2014-09-03 08:23:06

+0

嘗試''route'=>'/ crm/calendar [/:action [/:id]]'' – Xerkus 2014-09-03 10:14:09

回答

0

路由配置是否正確。該路線已經從另一個模塊路線寫入。這是問題。 ZF2並不容易檢查所有路線和路徑。

1

我認爲它可能是你必須添加'may_terminate' => true,

所以,你的路由定義看起來就像這樣:

'calendar' => array(
    'type' => 'segment', 
    'options' => array(
     'route' => '/crm/calendar[/:action][/:id]', 
     'constraints' => array(
      'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
      'id'  => '[0-9]+', 
     ), 
     'defaults' => array(
      'controller' => 'Crm\Controller\Calendar', 
      'action'  => 'index', 
     ), 
    ), 
    'may_terminate' => true, 
), 

嘗試是否可行。

否則,您也可以將其拆分並將crm設置爲文字路徑。

'crm' => array(
    'type' => 'literal', 
    'options' => array(
     'route' => '/crm', 
    ), 
    'may_terminate' => false, 
    'child_routes' => array(
     'calendar' => array(
      'type' => 'segment', 
      'options' => array(
       'route' => '/calendar[/:action][/:id]', 
       'constraints' => array(
        'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'id'  => '[0-9]+', 
       ), 
       'defaults' => array(
        'controller' => 'Crm\Controller\Calendar', 
        'action'  => 'index', 
       ), 
      ), 
     ), 
    ), 
), 

但最後這個方案意味着你將永遠有路由到crm/calendar

+0

我添加您的更改。但它仍然不起作用。 – 2014-09-03 09:43:01

+1

@Asuraya我只是嘗試在我自己的應用程序中,它的工作原理...你確定你沒有輸入錯別字,並且你的路由器沒有覆蓋你的應用程序的其他地方嗎? – Wilt 2014-09-03 14:53:36

+0

是的。這是問題。 crm路由已經從另一個模塊覆蓋。謝謝。 – 2014-09-04 04:20:59

0

可以看出CONFIGS應該糾正。 您是否試過沒有最後/(test.dev/crm/calendar,而不是test.dev/crm/calendar/)

相關問題