Question

I have following route defined

'kategoria' => array( 
                'type' => 'Zend\Mvc\Router\Http\Regex',
                'options' => array(
                    'regex'    => '(.*)/([0-9]+).htm',
                    'defaults' => array(
                        'controller' => 'Core\Controller\Index',
                        'action'     => 'index'
                    ),
                 'spec' => '%full_path%/%nodeID%.htm',    
                ),
            ),

I'm trying to get both params in action, but no success

$nodeID = $this->params()->fromRoute('nodeID');
$full_path = $this->params('full_path','');

How to get matched params from Regex router in ZF2 ? I'm using this router in ZF1.

Was it helpful?

Solution

In ZF2, you include the variable name in the pattern match, so you want something like this:

'regex' => '(?<full_path>.*)/(?<nodeID>[0-9]+).htm',

Then your code should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top