This seems like a very simple question, but I’ve only found complicated answers. I’ve got a Zend Framework application that requires users to login. The loginAction() and logoutAction() are defined in AuthController. I want to allow users to login via http://www.example.com/login rather than http://www.example.com/auth/login.
I know there are numerous ways of doing this, the 3 I’ve considered are:
- .htaccess rewrite
- Creating a LoginController and redirecting the indexAction() to auth/login
- Defining my own routes using Zend_Controller_Router_Rewrite.
I’d rather keep it out of #1 if possible. #2 is easy enough to understand, although it seems like a hack. It also could clutter the code with a bunch of 5-line “Controller” classes. I think #3 is the way to go but I don’t fully understand how to use it effectively. I have tried Using Zend_Config with the RewriteRouter although I only defined the login route so every link became ‘/login’ (I think I was missing a default route). I did this in my Bootstrap.php, I’m not sure if that was correct.
Is there a simple approach I’m missing? Am I using #3 incorrectly? Are there tutorials for this that I should read? (I’ve looked at the Zend documentation which is good but often I find myself asking, ‘Where should this code go: in a controller, model, bootstrap, other?’)
for a defined purpose like you have a “named” route would be the simplest way to do it. While there are any number of ways to implement a named route the easiest is to put it in the application.ini:
putting it in your bootstrap is not wrong, it just doesn’t seem as convienient to me.
Also doing it this way should (no guarantees) prevent any problems with the default routes.
When calling a route using the url() helper it is important to remember to use either the named route :
or if you need to pass the normal ‘controller’ => , ‘action’ => :
near as I can tell ‘default’ in this context indicates this would be a default route as defined in Zend/Controller/Router/Route/Module.php