As, Zend_View is a PHP based template engine, we use PHP within the file to display data from the model
and controller. The template file, index.phtml in this case, is executed within a member function of Zend_View
and so $this is available within the template file which is the gateway to Zend_View’s functionality. All
variables that have been assigned to the view from within the controller are available directly as properties of
$this, as can be seen by the use of $this->title within index.phtml. Also, a number of helper functions, are
provided for use by templates to make them easier to write.
The most commonly used helper function is escape(). This function is used to ensure that the output is
HTML-safe and helps to secure your site from Cross-Site Scripting (XSS) attacks. All variables that are not
expected to contain displayable HTML should be displayed via the escape() function. Zend_View’s
architecture is designed so that creating new helper functions is encouraged. For maximum flexibility, the
convention is that view helper functions return their data and then the template file echoes it to the browser.
With these four files in place, we have created a minimal Zend Framework application with all the pieces
in place ready for building a full scale website and you should now have a fundamental understanding of how
the pieces fit together. We will now look at what is happening within the Zend Framework’s code which is
providing the MVC foundation that our code has been built upon.
