views:

179

answers:

4

In my application i have the following classic template on 3 columns

*********************************************************
*                *
*                *
*********************************************************
*        *                               *              *
*        *                               *              *
* sidea  *         content               *    sideb     *
*        *                               *              *
*        *                               *              *
*        *                               *              *
*        *                               *              *
*        *                               *              *
*        *                               *              *
*********************************************************
*                                                       *
*                                                       *
*********************************************************

Where the header and sideb are similar for the most part of the site (side b contents depends on the user's state so they need to be rendered dynamicaly), and sidea & content changing for every controller.

Since I'm new to ZF (1.9), I have some difficulties to implement such setting, where script views reuse common methods (for the sideb), and there is 3 different places for dynamic contents injection. Can somebody hint any tutorial/code example?

Thanks in advance.

Edit

After some more deeper reader of zend_layout documentation and some other links (i.e. this post) i found out that i should concentrate my research in direction of Composite View pattern for zend framework, in particular Zend_View_helper_partial. Probably following two links can give me a hand (and to other folks searching the same thing)

Link 1 Link 2

+2  A: 

Looks like you need a layout. Have a look at the Zend_Layout doc page and see if that achieves what you want.

Check out this webinar for info on what's possible with Zend_Layouts

Neel
+1  A: 

View Helpers are useful for functions that get reused.

http://framework.zend.com/manual/en/zend.view.helpers.html

piddl0r
A: 

I'll echo that what you're looking for is a layout. With the layout you can have a controller render a view into different 'content' areas.

Combining this with the ability to 'forward' rom one controller to another, the main controller for a request could render a view (or multiple views) into the content placeholder, then forward to controllers that render (if needed) the sidebars/header/footer.

For views that don't require those elements (say the 'print' action for an article controller), you could just disable the layout, and render the view normally (without any forwarding to other controllers).

Tim Lytle
About forwarding: I've seen it in documentation (or it's analogue $this->action) and it seems to me to be too heavy solution for this kind of thing. I think that nested partial views are more easy to manage (for me and for designers). Check the second link in my post, it speaks about "why we shouldn't use action stack", which can be applied to _forward as well.
Alekc
Took a quick look at the article, and I don't agree (or disagree) completely. I think the concept of an action stack is just fine - perhaps the implementation not so much. For me, it makes sense, not in a web application, but a web site, where you may use a single controller for the main content area, but have sidebars/other content areas that should load different (and sometimes unrelated data). Perhaps that could all be done with view helpers, I just think something like an action stack would make sense for that.
Tim Lytle
Chapter 3 of 'Survive the Deep End' (http://www.survivethedeepend.com/zendframeworkbook/en/1.0/the.model) is very informative. I must admit that I had not though of just bypassing the controller (for read functions all that needs to happen is load model to view), and using a view helper.
Tim Lytle
+1  A: 

Use yout view script only for rendering the content of the page.

Utilize Zend_Layout to render the rest of the page and call the view helpers from your layout to populate your left and right sidebars.

If your 'sidea' is tied to your current action/controller you can render them from the actions view script and call the 'sideb' view helper from the layout.

You can of course render different parts of your view script to different response segments and use the layout file to put the response segment where you want it to be.

Forwarding to multiple controllers/actions is as Alekc wrote a huge impact on the performance of your application and is is quite unnecessary in this situation.

Goran Jurić