1

I want to remove index word from url from every action generated from index controller.

domain.com/index/user/id/1
It should be domain.com/user/id/1
and
domain.com/index/home
It should be domain.com/home

How can I do this? Please let me know if you have solution.
I am using zf1.12

1 Answer 1

1

You can do it in your Bootstrap.php (altough in application.ini). Add this to Bootstrap:

Bootstrap.php (untested)

/**
 * Setup Routig. 
 * Now all calls are send to indexController like
 * URL/ACTION-1
 * URL/ACTION-2
 *
 * @return void
 **/
protected function _initRouters()
{
    $router = Zend_Controller_Front::getInstance()->getRouter();

    $route = new Zend_Controller_Router_Route(
        ':action/*',
        array(
            'controller' => 'index',
            'action' => 'index'
        )
    );        

    $router->addRoute('default', $route);
}

Application.ini (untested)

routes.index.type = "Zend_Controller_Router_Route"
routes.index.route = "/"
routes.index.defaults.module = "default"
routes.index.defaults.controller = "index"
routes.index.defaults.action = "index"
Sign up to request clarification or add additional context in comments.

4 Comments

Its working fine for me but why this line Zend_Controller_Front::getInstance(). can we do this without creating instance.
Hum dont know, never tryed. Simply use applications.ini ;)
how this $router->addRoute( works in zend framework?
check the docs or this nice tutorial: blog.jebrini.net/post/1431025228/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.