Zend Framework url mapping issue

I am trying to map an action to a base url and a default controller.

Swear it should be straightforward or even a function out of the box, but how do you map the actions in your default controller to the base url using Zend Framework? I'm new to the Framework, so I hope I just miss something obvious.

Trying to match:

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

without breaking the settings of other default routes.

I can hack it with Zend_Router, but it breaks other rules for example. /: controller /: action /: module /: controller /: action

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

Examples of URL matching on request "tharkun" indexController has indexAction and contactAction methods need urls

/index
/index/contact
/
/contact

      

Second controller testController has indexAction and monkeyAction methods need urls

/test
/test/index
/test/monkey

      

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

+1


source to share


1 answer


The default controller is IndexController.

The display (default) works like this:

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

      

So add a custom route like this (will have a 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 the use of default routes.

Edit: As the comment says, this will break the indexAction of non-standard controllers.

+2


source







All Articles