Zend Framework -8:
In this current tutorial we will study about the view component of ZF. zend_view is the name of the component. It is very cumbersome if we want to put the styling code in each and every page of the html.
Instead of that we will initialize the view object in a particular folder and then we can use as per our requirement in the project. ViewRenderer is an action helper which helps to initialize the view properties. For rendering purpose ViewRenderer arrange the Zend_View object to get the view objects from views/scripts/<controller name> . It will render the script which is named after the action with .phtml extension. This file will be stored in views/scripts/<controller name>/<action name>.phtml. These all are developed by the Zend_Tool at the time of project creation.
Layout: HTML Code
In almost every project we need include header, footer and sidebar section to make our web pages presentable, but it is not a very easy task to do. Zend_Tool comes up with a solution and it also update the applicaion.ini file, all we need to do is to execute the following command in the command line:
zf enable layout
Using the above command Zend_Tool will create a folder named application/layouts/scripts and creates a view script called layout.phtml into it. Now open the file and replace the existing coding with the following:
$this->headTitle()->setSeparator(' - ');
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?phpecho $this->headMeta(); ?>
<?phpecho $this->headTitle(); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?phpecho $this->layout()->content; ?>