-1

I want add crm as prefix of CRM module.

This is router section in my 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',
                    ),
                ),
            ),

When i use test.dev/crm/calendar/index is working properly. But it is not working for test.dev/crm/calendar . I couldn't find any issue.

When i use 'route' => '/calendar[/:action][/:id]', i can use test.dev/calendar. But i need use prefix. How can i do it?

Wilt
  • 41,477
  • 12
  • 152
  • 203
Dinuka Thilanga
  • 4,220
  • 10
  • 56
  • 93
  • 3
    Your route config is correct, it must be something else. why is it 'not working'? What error do you get? – AlexP Sep 03 '14 at 08:15
  • config is correct. Because it is working in some url. When i use /crm/calender it is not redirect to related action. – Dinuka Thilanga Sep 03 '14 at 08:23
  • try `'route' => '/crm/calendar[/:action[/:id]]'` – Xerkus Sep 03 '14 at 10:14
  • You say you aren't redirected to the right action, but is another route matching instead, or do you get an exception? This would help us narrow down the problem. – Tim Fountain Sep 03 '14 at 10:38

3 Answers3

1

I think it might be that you have to add 'may_terminate' => true,

So your route definition will look like this:

'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,
),

Try if that works.

Otherwise you can also split it and make crm to a literal route.

'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',
                ),
            ),
        ),
    ),
),

But this last solution means that you will always have to route to crm/calendar

Wilt
  • 41,477
  • 12
  • 152
  • 203
  • 1
    @Asuraya I just tried in my own application and it works... Are you sure you you make no typos and that your router is not overwritten somewhere else in your application? – Wilt Sep 03 '14 at 14:53
  • Yes. That is the issue. crm route had override from another module. Thanks. – Dinuka Thilanga Sep 04 '14 at 04:20
0

As seen configs should correct. Did you tried without last / (test.dev/crm/calendar, not test.dev/crm/calendar/)

Dimiya
  • 43
  • 7
0

Route configuration is correct. This route had over write from another module route. That's the issue. ZF2 has not easy way to check all routes and paths.

Dinuka Thilanga
  • 4,220
  • 10
  • 56
  • 93