views:

591

answers:

4

What is the best way to embed Login Form into several pages in Zend Framework?

Currently I have two controllers, LoginController for separate login form and IndexController for actions on index page.

I need to include Login Form into index page to let users log in both from the front page and from Login page.

My current solution is to make IndexController extend LoginController, but I have to make some adjustments to the code of both controllers (e.g. call parent::IndexAction from inside child indexAction to render login form and various redirects should be updated too).

Is it OK implement "multi-page" login with such a controller inharitance?

What is the best practice?

A: 

Might be easier to just create your own form on your index page (careful to name the inputs as you had on your login page) and just set the action to your login script.

Erling Thorkildsen
+1  A: 

Action helpers may help you http://devzone.zend.com/article/3350-Action-Helpers-in-Zend-Framework

Irmantas
A: 

login should be better an action (function) into a user controller.

jipipayo
A: 

i also recommend you moving most of your code into the user model instead of the controller. I think "thin controllers, Fat models" pattern is more expendable and maintainable then extending controllers. I also use the extending a generic login controller for my aplications, but the generic controller just has a functions that gets the inputs and sends them to the model and redirects or sends an error to the view.

solomongaby