0

I'm struggling with this problem and can't get over it.

What I want to achieve is a route like this: /rolepermission[/:roleid]/permissions[/:permissionid][/action/:action]

Currently I came up with something like this:

        'rolepermission' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/rolepermission',
                'constraints' => array(),
                'defaults' => array(
                    'controller' => 'My\Controller\RolePermission',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'rolepermissionroleid' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/[:roleid]',
                        'constraints' => array(
                            'roleid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                            'action' => 'detail',
                        ),
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'rolepermissionpermissions' => array(
                            'type' => 'literal',
                            'options' => array(
                                'route' => '/permissions',
                                'constraints' => array(),
                                'defaults' => array(
                                    'action' => 'index'
                                ),
                            ),
                            'may_terminate' => true,
                            'child_routes' => array(
                                'rolepermissionpermissionid' => array(
                                    'type' => 'segment',
                                    'options' => array(
                                        'route' => '/[:permissionid]',
                                        'constraints' => array(
                                            'permissionid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                        ),
                                        'defaults' => array(
                                        ),
                                    ),
                                    'may_terminate' => true,
                                    'child_routes' => array(
                                        'rolepermissionaction' => array(
                                            'type' => 'segment',
                                            'options' => array(
                                                'route' => '/action/[:action]',
                                                'constraints' => array(
                                                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                ),
                                                'defaults' => array(
                                                    'action' => 'index'
                                                ),
                                            ),
                                            'may_terminate' => false,
                                            'child_routes' => array(),
                                        ),
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),

When routing to /rolepermission/permissions I constantly get 'permissions' substituted for :roleid. I'm expecting here nothing to be substituted due to not passing a roleid. What am I doing wrong?

Thanks in advance, cheers

kinkee
  • 368
  • 2
  • 12
  • ive not used routes in this way but 'roleid' => '[a-zA-Z][a-zA-Z0-9_-]*', is set to allow any alphanumerical or underscore or hyphen. does your ID column really contain these chars? because i would hazard a guess that is why it is assuming that you are entering a roleid when you are not. You could try and do this by writing all of them out 1 by 1 then merge them afterwards. – mic Jun 04 '13 at 14:52
  • Thank you for your advice micb. The roleid is an alphanumerical id, e.g.: 'Admin'. It works when defining the route as single route without children ('route' => /rolepermission[/:roleid]/permissions[/:permissionid][/action/:action]), but I need the whole route defined with children for correct route matching. – kinkee Jun 04 '13 at 15:32

1 Answers1

1

Solved the problem temporarily by adapting the 'rolepermissionpermissions' child route as following:

'rolepermission' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/rolepermission',
                'constraints' => array(),
                'defaults' => array(
                    'controller' => 'My\Controller\RolePermission',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'rolepermissionroleid' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/:roleid',
                        'constraints' => array(
                            'roleid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                            'action' => 'detail'
                        ),
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'rolepermissionpermissionid' => array(
                            'type' => 'segment',
                            'options' => array(
                                'route' => '[/permission/:permissionid]',
                                'constraints' => array(
                                    'permissionid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                ),
                                'defaults' => array(
                                    'action' => 'detail',
                                ),
                            ),
                            'may_terminate' => true,
                            'child_routes' => array(
                                'rolepermissionaction' => array(
                                    'type' => 'segment',
                                    'options' => array(
                                        'route' => '/action/:action',
                                        'constraints' => array(
                                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                        ),
                                        'defaults' => array(
                                            'action' => 'detail'
                                        ),
                                    ),
                                    'may_terminate' => true,
                                    'child_routes' => array(),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),

Although it's indeed not the best solution, this works for now.

kinkee
  • 368
  • 2
  • 12