Question

What im trying to achieve:

domain.com/user                    = UserController::index
domain.com/user/profile            = UserController::profile
domain.com/user/profile/9          = UserController::profile (with query param id=9)
domain.com/user/profile/9/edit     = UserController::editProfile (with query param id=9)

So i have the following route:

'user' => array(
    'type'    => 'Segment',
    'options' => array(
        'route'    => '/user',
        'defaults' => array(
            '__NAMESPACE__' => 'YrmUser\Controller',
            'controller'    => 'User',
            'action'        => 'index',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'profile' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/profile[/:id]',
                'defaults' => array(
                    'action' => 'profile',
                ),
                'constraints' => array(
                    'id' => '[0-9]*'
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'edit' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/edit',
                        'defaults' => array(
                            'action' => 'editProfile',
                        ),
                    ),
                    'may_terminate' => true
                ),
            )
        ),
    )
)

It kinda works, except for the fact that the query parameter ID never gets a value. Anyone who can tell me what i'm doing wrong, im guessing its something stupidly simple...

Thanks in advance,

Yrm

Was it helpful?

Solution

Works for me.

I var_dumped the $this->params ('id') in the action and got this:

/user
null

/user/profile
null

/user/profile/99
string '99' (length=2)

/user/profile/99/edit
string '99' (length=2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top