1
votes

I'm trying to map an action to the base URL and default controller.

Swear this should be straight forward or even an 'out the box' feature but how do you map actions in your default controller to the base url using the Zend Framework? I'm fairly new to the Framework so I'm hoping I'm just missing something obvious.

Trying to map:

domain.com/index/my-page to domain.com/my-page

without breaking any of the other routes setup by default.

I can hack it using the Zend_Router but it breaks the other rules e.g. /:controller/:action /:module/:controller/:action

note: /index/my-page is an example url - I need it to work for all the indexController actions dynamically.

URL Mapping examples as requested by 'tharkun' indexController has methods indexAction and contactAction need urls

/index
/index/contact
/
/contact

2nd controller testController has methods indexAction and monkeyAction need urls

/test
/test/index
/test/monkey

basically - if the sys can't find a controller of VAR then it looks for a action of VAR in the default controller

1
apologies should have made it clearer that was just my example url - I need it to work for all the indexController actions dynamically, when I add regex's and catches is when it starts to break the other default routers.coffeerings

1 Answers

2
votes

The default controller is IndexController.

The (default) mapping works like this:

/ => IndexController::indexAction
/index => IndexController::indexAction
/index/foo => indexController::fooAction
/foo => FooController::indexAction

So, add a user defined route like this (will have lower priority than the default)

$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route(
    '/:action',
    array(
        'controller' => 'index'
    )
);
$router->addRoute('user', $route);

This did not break my use of the default routes.

Edit: As coffeerings said in the comment, this will break the indexAction of non-default controllers.