Analysis of usage of Zend_view components in Zend framework

Source: Internet
Author: User
Tags php foreach zend zend framework
This article mainly introduces the use of Zend_view components in the Zend Framework, combined with the example form to briefly analyze the Zend_view component view operation of the relevant skills and considerations, the need for friends can refer to the following

This example describes the Zend_view component usage of the Zend Framework Getting Started tutorial. Share to everyone for your reference, as follows:

The Zend_view component can implement the separation of the code in the view part of the MVC pattern from the model and controller parts.

Use steps: First establish a Zend_view instance in the controller and pass the required variables to it, then the controller notifies Zend_view to display a specific view,

Generates the contents of the view output.

Instance of the controller code script:

<?PHP//uses models to obtain book author and title related Data $data = array (  ' author ' and '    Cao Xueqin ',    ' title ' = ' Red Mansions '  ),  Array (' Author ' = ' in ' The '    Luo Guan ',    ' title ' = ' Kingdoms '  ),  Array (    ' author ' = ' Wu Chengen ',    ' title ' = > ' Journey to  the Monkey '),  Array (    ' author ' = ' Shi Naian ',    ' title ' = ' Outlaws '))  ;//pass data to Zend_ Instance of view class require_once ' zend/loader.php '; Zend_loader::loadclass (' Zend_view '); $view = new Zend_view (); $view->books = $data; $view->setscriptpath ('./'); echo $view->render (' 4-2.php ');

View script code (contents in 4-2.php):

<?php if ($this->books):?><table>  <tr>    <th> author </th>    <th> title < /th>  </tr>  <?php foreach ($this->books as $key = $val):?>  <tr>    <td ><?php echo $this->escape ($val [' author '])?></td>    <td><?php Echo $this->escape ($ val[' title ')?></td>  </tr>  <?php endforeach;? >  </table><?php else:?><p> No need for bibliography </p><?php endif;? >

Execution Result:

   The title of the author Cao Xueqin   kingdoms Wu Chengen journey to the   Shi Naian   Outlaws of the red Chamber

Summary (Practical experience):

This case, and there is not much structure, zend_view equivalent to a plug-in, can be flexible call. The content in the Zend Framework does not need to be used in a very large architecture.

MVC is not so stiff, it's just a thought. The M-Layer here is a set of arrays. During the real development process, the information should be read from the database. The view-level directory is $view->setscriptpath ('./') and is set to the current directory.

This makes it possible to directly invoke the file 4-2.php in the current directory. After the view layer receives the data, it takes some processing.

The main function of Zend_view is to pass data from the controller layer to the view layer.

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.