Two-Step view in Zend Framework 1.0.0

Paulo Nei wrote an email to fw-general which is, I suspect a very common issue that people are going to run into:


Hi,

I wanna put header & footer in all view templates.

But with ZF I don't got an easy way to do it

...

At the moment, the Zend Framework doesn't have an "officially blessed" solution, so there are multiple approaches being used:

1. Front Controller plug-in.
http://www.nabble.com/Controller-and-View-Question-tf3462561.html

2. Zend_Layout proposal.
http://framework.zend.com/wiki/display/ZFPROP/Zend_Layout

3. Zend_View Enhanced proposal.
http://framework.zend.com/wiki/pages/viewpage.action?pageId=33071

4. Extend ViewRenderer directly.
http://akrabat.com/2007/06/02/extending-viewrenderer-for-layouts/

The wiki is down again, so I could have got the links to 2 and 3 wrong!

At the moment, I'm using (4) as it's simple. It does introduce problems if you want to use _forward() though, so if you are an _forward() person, then 1, 2 or 3 are better choices.

Update (04/Sep/2007): Also: http://www.spotsec.com/blogs/archive/the-basics-of-zend_layout-ahem-xend_layout.html

If you would like to comment on this article, please ping me on twitter.
If your response won't fit into 140 characters, write a blog post and then ping me!