0
votes

I've been writing a project since some time and I've used the default routing, the :module\:controller:\:action. After some time, I've added some routers to my config like:

resources.router.routes.page.route = "page/:slug"
resources.router.routes.page.defaults.module = "default"
resources.router.routes.page.defaults.controller = "pages"
resources.router.routes.page.defaults.action = "view"
resources.router.routes.page.defaults.slug = ""

But, after that, when I click on some link generated by view URL helper with one of the new routes all other links ignore some of given paramters. Example, I've got route:

resources.router.routes.project.route = "project/:slug"
resources.router.routes.project.defaults.module = "projects"
resources.router.routes.project.defaults.controller = "projects"
resources.router.routes.project.defaults.action = "view"
resources.router.routes.project.defaults.slug = ""

If I go to a link /project/test then link like this:

$this->url(
    array('module' => 'admin', 'action' => 'list-users', 'controller' => 'users')
, null,true
);

will point to "/project"

Is there any possibility to maintain the default routing on top of custom routes? Can I add some default router that will work the same as the default one? It's probably something simple but I maybe missed the point. Thanks for all the help.

I've added something like this but with no effect:

resources.router.routes.default.route = ":module/:controller/:action"
resources.router.routes.default.defaults.module = "default"
resources.router.routes.default.defaults.controller = "pages"
resources.router.routes.default.defaults.action = "view"
resources.router.routes.default.defaults.slug = ""
2
Please define "dont work" - do you get an error, or do the links point to the wrong place?Tim Fountain
Ok, I've added some more infoBartosz Rychlicki
If you pass 'default' as the second param to the url helper instead of null does that make any difference?Tim Fountain
Yep, then it works. But Should the default be chosen when I pass null? I really would like to refactor all of those helpers call :-)Bartosz Rychlicki

2 Answers

0
votes

In order for you to set your custom routing, you need to get the router component and pass your routes into it.

This is how I did mine in a project I am working on. In your Bootstrap class, you create the following function

protected function _initRoutes()
{
    $this->bootstrap('frontcontroller');
    $front = Zend_Controller_Front::getInstance();
    $router = $front->getRouter();
    $myRoutes = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini','production');
    $router->addConfig($myRoutes,'routes');

This calls the front controller and gets the router from it. I then pass my routes config into it.

I hope this answers your question.

0
votes

The problem is that the options for url helper are as follows:

url($urlOptions, $name, $reset)

Therefore, when you set $name to null, current route ('project') is used. Not event setting $reset to true will help. Replace null with 'default' and it should work.