Layouts in Zend Framework 1: one template around every page
How Zend_Layout wrapped every page in a single shared template, and how to switch or turn it off.
From the archive: in 2011 I shared “Managing Zend Framework Layouts” by W. Jason Gilmore, phpBuilder (2010) on my old blog. This page is a short summary in my own words; the original belongs to its author.
Before frameworks, many PHP sites stitched pages together with include 'header.php' and include 'footer.php'. Zend Framework 1’s Zend_Layout replaced that with one layout template wrapped around every page’s content (the “two-step view” pattern).
- Turn it on:
zf enable layoutcreateslayout.phtml; inside it,<?php echo $this->layout()->content; ?>marks where each page goes. - Use another layout for one action:
$this->_helper->layout->setLayout('admin'); - No layout at all (for AJAX or downloads):
$this->_helper->layout->disableLayout();
Today: in Laminas MVC (Zend Framework’s successor) the layout is set in the view manager configuration, and a controller can switch it with $this->layout('layout/admin'). See also how to skip the view or layout in ZF2.
Read the original: Managing Zend Framework Layouts, by W. Jason Gilmore, phpBuilder (2010).