Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^268) CHAPTER 17 ■ THE ZEND FRAMEWORK APPLIED
Listing 17-11. Bootstrapping Zend_Layout (in index.php)
Zend_Layout::startMvc(
array(
'layoutPath' => APP_PATH. '/application/layouts/',
'layout' => 'index'
)
);
This bootstrap process defines a location for the layout script files, as well as the name of
the default layout. In this case, to demonstrate the option, you’ve overridden the default name,
layout, with index.
Next, create the layout file, index.phtml, as shown in Listing 17-12.
Listing 17-12. Master Layout (./application/layouts/index.phtml)




layout()->content; ?>


When Zend_Layout is active, all of the output from your actions will be placed into the
Zend_Layout->content placeholder. This placeholder can be accessed via the layout helper
($this->layout()), as shown in Listing 17-12.
At the controller and action levels, you can choose alternative layouts by calling setLayout()
either from init() or within an action:
$this->_helper->layout()->setLayout('alternative');
To disable layouts for an action, call disableLayout():
$this->_helper->layout()->disableLayout();

Using Placeholders.


In addition to storing the output of actions, placeholders can be used to place content in
predefined locations within the layout. A common use is to place an item in a menu, but to
configure it from within a view script.
To create a layout that has a menu system, you would define a placeholder under the
Zend_Layout name using a custom key 'menu'. Listing 17-13 demonstrates how to create this
as a basic layout template.

McArthur_819-9.book Page 268 Friday, February 29, 2008 8:03 AM

Free download pdf