Nuramon
Nuramon

Reputation: 1242

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?

Upvotes: 0

Views: 549

Answers (2)

Tim Fountain
Tim Fountain

Reputation: 33148

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');

Upvotes: 1

David Weinraub
David Weinraub

Reputation: 14184

Your Regex route doesn't have a page parameter, so when the url view-helper ends up calling Route::assemble() with the parameters you feed it, it ignores your page value.

The two choices that come to mind are:

  1. Modify your regex to include a (probably optional with default value) page parameter
  2. Manage the page parameter outside of your route in the query string.

Upvotes: 1

Related Questions