0
votes

I have four child_routes that call the same controller and action.


    'noticia' => array(
        'type'    => 'Segment',
        'options' => array(
            'route' => 'noticia[/:slug]',
            'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            ),
            'defaults' => array(
                '__NAMESPACE__' => 'Application\Controller',
                'controller'    => 'Post',
                'action'        => 'index',
            ),
        ),
    ),
    'dica' => array(
        'type'    => 'Segment',
        'options' => array(
            'route' => 'dica[/:slug]',
            'constraints' => array(
                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            ),
            'defaults' => array(
                '__NAMESPACE__' => 'Application\Controller',
                'controller'    => 'Post',
                'action'        => 'index',
            ),
        ),
    ),
    'ovarejao' => array(
        'type'    => 'Segment',
        'options' => array(
            'route' => 'o-varejao[/:slug]',
            'constraints' => array(
                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            ),
            'defaults' => array(
                '__NAMESPACE__' => 'Application\Controller',
                'controller'    => 'Post',
                'action'        => 'index',
            ),
        ),
    ),
    'servicos' => array(
        'type'    => 'Segment',
        'options' => array(
            'route' => 'servicos[/:slug]',
            'constraints' => array(
                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            ),
            'defaults' => array(
                '__NAMESPACE__' => 'Application\Controller',
                'controller'    => 'Post',
                'action'        => 'index',
            ),
        ),
    ),

What I need is to pass a parameter so that I can differentiate these routes. How do?

1

1 Answers

1
votes

I think your structure is a little off. Why do you have four different routes for one action of one controller? This pretty much makes no sense.

Rather route each of the routes you've set up so far servicos, ovarejao, dica, noticia to the PostController with similar actions like servicosAction, ovarejaoAction, dicaAction and noticiaAction

If the actions are very similar in their respective views, you could use one template for all actions, too, that would make the templating a little easier. This is done like:

public function servicosAction()
{
    $vm = new ViewModel();
    $vm->setTemplate('namespace/post/multiple.phtml');

    // Grab data from your model here with some parameter

    return $vm->setVariables(array(
        //key-value paired array of view variables
    ));
}

In case this doesn't meet your criteria, please make your problem more clear. What exactly is it, that you want to achieve?