zend-frameworkzend-routezend-config

hide the index controller from the URL for a single module


After creating a modular structure for a single module would prevent the url appears the name of the controller.

everything works with the defaul

site.con/foo/index/action/

I wish I could write as

site.com/foo/action/

being IndexController the only controller that module.

I have tested several solutions but do not work. Being the first app with ZF I do not quite clear the steps to be taken.


Solution

  • You need Zend Routes.

    Define routes in your

    bootstrap.php

    Open your bootstrap.php and put the following:

    function _initRoutes() {
            $front_controller = Zend_Controller_Front::getInstance();
            $router = $front_controller->getRouter();
            $router->addRoute('foo-action', new Zend_Controller_Router_Route(
                '<foo module name>/<action name>', array('module' => 'foo', 'controller' => 'index', 'action' => '<action-name>')
            ));
    }
    

    PS:Worked / Didn't work? Mention in comments and if didn't work, give proper names of module, controller and action.

    EDIT:

    How to set default controller / module in application.ini

    routes.index.type = "Zend_Controller_Router_Route"
    routes.index.route = "/"
    routes.index.defaults.module = "<module name>"
    routes.index.defaults.controller = "index"
    routes.index.defaults.action = "index"
    

    Solves it?