0

I have been trying to shortern this route:
http://abc.localhost/user/view/index/id/1

to this:
http://abc.localhost/user/1

with the following portion of code in my bootstrap but I keep getting an error stating that the 'Reversed route is not specified', any ideas why?

$route = new Zend_Controller_Router_Route_Regex(
    'user/(\d+)',
    array(
        'module'        => 'user',
        'controller'    => 'view',
        'action'        => 'index'
    ),
    array(
        1 => 'id'
    )
);
$router->addRoute('user', $route);

Thanks,
Martin

1 Answer 1

4

If you want to use the URL helper with Regex routes you need to pass a 4th parameter to Zend_Controller_Router_Route_Regex that it can use to rebuild the route. This 4th parameter should be a string in a sprintf-format which it can inject the params into.

In your case it would be something like:

$route = new Zend_Controller_Router_Route_Regex(
    'user/(\d+)',
    array(
        'module'        => 'user',
        'controller'    => 'view',
        'action'        => 'index'
    ),
    array(
        1 => 'id'
    ),
    'user/%d'
);
$router->addRoute('user', $route);

There is some info on this right at the end of the manual section on Regex routes: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.regex - but it's easy to miss.

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.