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:
<?php
$this
->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');$this
->headTitle()->setSeparator(' - ');echo
$this->doctype(); ?><
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><
head><?php
echo $this->headMeta(); ?><?php
echo $this->headTitle(); ?><?php
echo $this->headLink()->prependStylesheet($this->baseUrl().'css/site.css');?></
head><
body><
div id="content"><
h1><?php echo $this->escape($this->title); ?></h1><?php
echo $this->layout()->content; ?></
div></
body>If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.