Skip Navigation LinksHome > Categories > Code from a Category

Introduction to the Zend Framework: Part Three.

User Name: serfcompany
Name: Serf
Contact Me:
Home Page:
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 1484
Add Date: 06/06/2012
In this article I will show you how you can conveniently make a conclusion we need the data in the required form on the screen.

For this class is designed Zend_View, with which you can easily implement a "look" of the pattern MVC (model-view-controller or a model-view-controller).

Working on Zend_View

Zend_View - a class PHP framework Zend Framework, designed to separate the soft part of the development of the site from its design. That is, first written in the software part, and then executed scripts, where we will use a minimum of code.

Working with Zend_View is to create a variable inside a class instance Zend_View and the use of these variables in a script form.
By default, Zend_View on and it handles the scripts are in the folder «/ application / views / scripts / {controller} / {action}. Phtml».
Each script type is a normal html document inserts php code.

Let's modify our application to work with Zend_View and write the output of all the news site, and pages for creating and editing news site, you then create yourself (for a better understanding of the material)

So, create a file «index.phtml» in the folder «/ application / views / scripts / news /» and write it in code like this:

In the above code, object $ this this is our object Zend_View, in which we have created a few variables from the controller. The code I have used the abbreviated design PHP, for convenience. For example, it is easier to write:


Note: The short construction work only if the server configuration directive is enabled short_open_tags. But at the moment short_open_tags = off - a rarity.

See how easy it is to issue a similar project in order to explore the full functionality Zend_View read the official manual (I'm too lazy to describe everything, when in the manual easy to understand itemized). Zend_View allows you to break your pages into small pieces, such as a hat can be written once for all pages, and then connect it to different types of scripts. This approach has many advantages:

  • when the cap will not have to edit all the scripts;
  • prevent duplication of commonly used code;
  • anything extra is not confused in your scripts. You are only working on the design of the body of the document!

    Do not forget to write the following code in our controller, otherwise our project will not work:

    In a previous article there are almost no changes. Were added only to the lines where I'm working with Zend_View. They are very trivial, and to understand their work is based on the material described is very simple. As a "homework" I recommend you create a view script for adding and editing of news. To delete a news view script is not needed, because in the end we will redirect your browser to a different address (if you can bring something to the user, removing the redirect :)).

    Good luck in your endeavors!

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.