0

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?

2 Answers 2

1

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');
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, completely forgot about the third parameter, to restrict the values. I'll go with your solution, seems more flexible, thanks!
1

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.

2 Comments

Thanks, 1. could get quite complex, when I want more parameters, but 2. is a good workaround, but requires a new Url Helper. Tim's solution seems to be the best in my case. :) (Sorry I can set only one answer to be the "correct one".)
No sweat, glad we could both help. Cheers. ;-)

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.