1
votes

I'm using routing setup in a module.config.php file within Zend Framework 2, it directs to the correct controller and action but is failing to pass through the additional page param, here's the config code:

'admin-management' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/admin/accounts/[:action]/[page/:page]',
                'constraints' => array(
                    'page' => '[0-9]*',
                ),
                'defaults' => array(
                    '__NAMESPACE__' => 'UserManagement\Controller',
                    'controller'    => 'Management',
                    'action'        => '[a-zA-Z][a-zA-Z0-9_-]*',
                ),
            ),
        ),

To check the parameters that come through I'm using the following in the controller users action:

    $page = $this->params()->fromQuery();
    echo __FILE__; echo '<pre>'; print_r($page); echo '</pre>'; exit;

Array is empty requesting the following url: http://myapp.dev/admin/accounts/users/page/123

Incidentally if I add ?page=123 to the end the param does show correctly...

1

1 Answers

1
votes

fromQuery() pulls variables from the query string specifically. What you want is:

$page = $this->params()->fromRoute('page');

See: http://framework.zend.com/manual/2.3/en/modules/zend.mvc.plugins.html#params-plugin