1

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.