6

I am trying here to create url, like:

/admin/login
/moderator/login

both the request would be served by same controller & action made for login, i.e. /account/login/<type>

Currently, all I am able to make the following URL:

/login/admin

/login/moderator

My current config file looks like the following:

resources.router.routes.login.route = "login/:type"
resources.router.routes.login.defaults.controller = "account"
resources.router.routes.login.defaults.action = "login"

I can't figure out, on how to put the type variable at the start of URL, I tried it but it gives server error. edit

I got this done, but can't understand why this didn't work earlier:

resources.router.routes.login.route = ":type/login"
resources.router.routes.login.defaults.controller = "account"
resources.router.routes.login.defaults.action = "login"

edit

Is it possible to make this arrangement more flexible, so that: /login => /admin/login

I am not looking for solution via .htaccess

Keval Domadia
  • 4,768
  • 1
  • 37
  • 64
s_s_
  • 463
  • 5
  • 20

1 Answers1

4

Add the following to your Bootstrap.php

function _initRoutes() {
    $front_controller = Zend_Controller_Front::getInstance();
    $router = $front_controller->getRouter();

    $router->addRoute('login', new Zend_Controller_Router_Route(
        '/:type/login', array('controller' => 'account', 'action' => 'login')
    ));
}

from your loginAction() use:

$this->getRequest()->getParam('type');

Simple?

Keval Domadia
  • 4,768
  • 1
  • 37
  • 64
  • thanks for your answer here, can you provide me something that could help me redirect `/login` => `/admin/login` – s_s_ Aug 30 '12 at 13:07
  • Though i was able to get solutions for this by application.ini, i didn't understand why this didn't worked earlier – s_s_ Aug 30 '12 at 13:08
  • From Login to /admin/login can be bit tricky! I would suggest redirecting `/login` to say a test controller and test action which would redirect to `/admin/login`. However if you want admin as in Controller admin and Login as in Action Login then, I can edit my answer for you. PS: If this resolves your query, how about a tick next to my answer? :P – Keval Domadia Aug 30 '12 at 13:32