Search code examples
phpzend-frameworkzend-route

Zend Url View Helper not working with Regex Routes


I'm using Zend Framework 1.12 and have this route:

$router->addRoute('item_start',
    new Zend_Controller_Router_Route_Regex(
            '(foo|bar|baz)',
            array(
                'module'        => 'default',
                'controller'    => 'item',
                'action'        => 'start'
            ),
            array(
                1 => 'area'
            ),
            '%s'
        )
);

Problem is, when I call '/foo' and use the Url Helper in the View, it doesn't give me any parameters:

$this->url(array("page"=>1));
// returns '/foo' (expected '/foo/page/1')

$this->url(array("page"=>1), "item_start", true);
// also returns '/foo'

Any idea how to get the page-parameter into the URL? I can't use the wildcard like in the standard route, can't I?


Solution

  • In addition to David's suggestions, you could change this route to use the standard route class, and then keep the wildcard option:

    $router->addRoute('item_start',
        new Zend_Controller_Router_Route(
                ':area/*',
                array(
                    'module'        => 'default',
                    'controller'    => 'item',
                    'action'        => 'start'
                ),
                array(
                    'area' => '(foo|bar|baz)' 
                )
            )
    );
    
    // in your view:
    echo $this->url(array('area' => 'foo', 'page' => 1), 'item_start');