1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="learning.layout.intro">
4 <title>Introduction</title>
7 When building a website using Zend Framework <acronym>MVC</acronym> layers, your view
8 scripts will typically be just snippets of <acronym>HTML</acronym> pertinent to the
9 requested action. For instance, if you had the action "<filename>/user/list</filename>",
10 you might create a view script that iterates through the users and presents an unordered
14 <programlisting language="php"><![CDATA[
17 <?php if (!count($this->users)): ?>
18 <li>No users found</li>
20 <?php foreach ($this->users as $user): ?>
22 <?php echo $this->escape($user->fullname) ?>
23 (<?php echo $this->escape($user->email) ?>)
31 Since this is just a snippet of <acronym>HTML</acronym>, it's not a valid page; it's missing
32 a <acronym>DOCTYPE</acronym> declaration, and the opening <acronym>HTML</acronym> and
33 <acronym>BODY</acronym> tags. So, the question is, where will these be created?
37 In early versions of Zend Framework, developers often created "header" and "footer" view
38 scripts that had these artifacts, and then in each view script they would render them. While
39 this methodology worked, it also made it difficult to refactor later, or to build composite
40 content by calling multiple actions.
44 The <ulink url="http://martinfowler.com/eaaCatalog/twoStepView.html">Two Step View</ulink>
45 design pattern answers many of the issues presented. In this pattern, the "application" view
46 is created first, and then injected into the "page" view, which is then presented to the
47 client. The page view can be thought of as your site-wide template or layout, and would have
48 common elements used across various pages.
52 Within Zend Framework, <classname>Zend_Layout</classname> implements the Two Step View