views:

542

answers:

3

I have a login button in the header of the website. This header's html is programmed into Zend framework views/layouts/home.phtml.

I have a hidden form in this layout that is triggered by jQuery thickbox inline content display integration. Reason, I dont want to make a ajax call to just fetch a small login form.

I create the form using Zend_Form and the problem is that I have to do it in all the controllers after checking if the user is logged in or not. I want to place this form generation in one single place, say in bootstrap and then have a logic in bootstrap to say that if user is logged in dont generate the form.

I don't know if bootstrap is the right place to do so or should I do it in some other place.

So, where should I instantiate the form so that its available everywhere if user is not logged in.

+1  A: 

Create your own base controller which extends Zend_Controller_Action then have your controllers extend off of your base controller. I don't know what "jQuery thickbox inline content display integration" is...but you have several sections you can put it in depending when you need your code to run. init(), preDispatch(), postDispatch() etc... Just make sure when you extend off your base controller that you do sthing like:

parent::init() parent::preDispatch() parent::postDispatch() etc... within each section so that the base code runs as well...

joedevon
+1  A: 

I did it in a different way, extendingZend_Controller_Plugin_Abstract to implement a plugin and register it with front controller.

public function routeStartup(Zend_Controller_Request_Abstract $request) { }

generated the form inside the above mentioned method and by setting the form in $view object.

$view can be retrived using :

$view = Zend_Layout :: getMvcInstance()->getView();
Pradeep Sharma
A: 

Hi Pradeep, i have a similar problem. I need to include a common Contact Us page in all controller but don't know how to do it. I think the method you describe above may solve my problem. can you please describe it more with some sample code?

riyas kp