2014-09-03 126 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/)

相关问题