3

How do I write a route in zf2 that allows for routes like /:controller/:action/* in zf1?

So that it can cater for parameters like controller/action/id/1/page/2 and controller/action?id=1&page=2 ?

A route that caters for parameters like controller/action?id=1&page=2 world be useful for ajax requests.

So my current code looks like this in my module.config.php

return array(
'controllers' => array(
    'invokables' => array(
        'Support\Controller\Support' => 'Support\Controller\SupportController',
    ),
),

'router' => array(
    'routes' => array(
        'support' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/support[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Support\Controller\Support',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'support' => __DIR__ . '/../view',
    ),
),
Kenneth
  • 91
  • 2
  • 7

2 Answers2

0

A look at the docs for Zend\Mvc\Router and a quick root around in the module.config.php file for the Application module in the Zend Skeleton Application tell me that you need to set up a route segment router that will match the url's you want to create.

As well as the Zend Framework docs, there is this slide show introduction to routing in Zend Framework which you may find useful. It has code examples of what you want to achieve.

vascowhite
  • 18,120
  • 9
  • 61
  • 77
  • Thanks so much for your reply. I've based my application off the Skeleton Application and I've read through the slide show link you gave. It does say for a segment route that it does support optional segments (both literal and parameter parts). I'm just not quite sure how. Maybe I'm missing something fundamental here. – Kenneth Oct 21 '12 at 20:17
0

Take a look at the following question and answer:

How can you add query parameters in the ZF2 url view helper

I would attempt to set-up a route and then adding a child route that uses Zend\Mvc\Router\Http\Query.

Community
  • 1
  • 1
DrBeza
  • 2,241
  • 1
  • 16
  • 18