Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Zend_View, the view component of Zend Framework

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "Zend Framework view component Zend_View how to use", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "Zend Framework view component Zend_View how to use" this article.

The details are as follows:

Zend_View is the view component of Zend Framework and the view layer in MVC. Zend_View is also the page of the application that is displayed directly to the user. Here is an introduction to the implementation class of Zend_View and how it is combined with Controller.

The realization of View

Zend_View is mainly implemented through classes in the following directories:

Root@coder-671T-M:/library/Zend# tree | grep View.php

│ └── View/

├── View.php

Root@coder-671T-M:/library/Zend/View# tree

.

├── Abstract.php

├── Exception.php

├── Helper

│ ├── Abstract.php

│ ├── Action.php

│ ├── BaseUrl.php

│ ├── Currency.php

│ ├── Cycle.php

│ ├── DeclareVars.php

│ ├── Doctype.php

│ ├── Fieldset.php

│ ├── FormButton.php

│ ├── FormCheckbox.php

│ ├── FormElement.php

│ ├── FormErrors.php

│ ├── FormFile.php

│ ├── FormHidden.php

│ ├── FormImage.php

│ ├── FormLabel.php

│ ├── FormMultiCheckbox.php

│ ├── FormNote.php

│ ├── FormPassword.php

│ ├── Form.php

│ ├── FormRadio.php

│ ├── FormReset.php

│ ├── FormSelect.php

│ ├── FormSubmit.php

│ ├── FormTextarea.php

│ ├── FormText.php

│ ├── Gravatar.php

│ ├── HeadLink.php

│ ├── HeadMeta.php

│ ├── HeadScript.php

│ ├── HeadStyle.php

│ ├── HeadTitle.php

│ ├── HtmlElement.php

│ ├── HtmlFlash.php

│ ├── HtmlList.php

│ ├── HtmlObject.php

│ ├── HtmlPage.php

│ ├── HtmlQuicktime.php

│ ├── InlineScript.php

│ ├── Interface.php

│ ├── Json.php

│ ├── Layout.php

│ ├── Navigation

│ │ ├── Breadcrumbs.php

│ │ ├── HelperAbstract.php

│ │ ├── Helper.php

│ │ ├── Links.php

│ │ ├── Menu.php

│ │ └── Sitemap.php

│ ├── Navigation.php

│ ├── PaginationControl.php

│ ├── Partial

│ │ └── Exception.php

│ ├── PartialLoop.php

│ ├── Partial.php

│ ├── Placeholder

│ │ ├── Container

│ ├── Abstract.php

│ ├── Exception.php

│ └── Standalone.php

│ │ ├── Container.php

│ │ ├── Registry

│ └── Exception.php

│ │ └── Registry.php

│ ├── Placeholder.php

│ ├── RenderToPlaceholder.php

│ ├── ServerUrl.php

│ ├── TinySrc.php

│ ├── Translate.php

│ ├── Url.php

│ └── UserAgent.php

├── Interface.php

└── Stream.php

6 directories, 70 files

Integration of Zend_View and Zend_Controller

Mainly in the Zend_Controller_Action class

/ * Initialize View object * * Initializes {@ link $view} if not otherwise a Zend_View_Interface. * * If {@ link $view} is not otherwise set, instantiates a new Zend_View * object, using the 'views' subdirectory at the same level as the * controller directory for the current module as the base directory. * It uses this to set the following: *-script path = views/scripts/ *-helper path = views/helpers/ *-filter path = views/filters/ * * @ return Zend_View_Interface * @ throws Zend_Controller_Exception if base view directory does not exist * / public function initView () {if (! $this- > getInvokeArg ('noViewRenderer') & & $this- > _ helper- > hasHelper (' viewRenderer')) {return $this- > view } require_once 'Zend/View/Interface.php'; if (isset ($this- > view) & & ($this- > view instanceof Zend_View_Interface)) {return $this- > view;} $request = $this- > getRequest (); $module = $request- > getModuleName (); $dirs = $this- > getFrontController ()-> getControllerDirectory (); if (empty ($module) |! isset ($dirs [$module])) {$module = $this- > getFrontController ()-> getDispatcher ()-> getDefaultModule () } $baseDir = dirname ($dirs [$module]). DIRECTORY_SEPARATOR. 'views'; if (! file_exists ($baseDir) | |! is_dir ($baseDir)) {require_once 'Zend/Controller/Exception.php'; throw new Zend_Controller_Exception (' Missing base view directory ("). $baseDir. '"));} require_once' Zend/View.php'; $this- > view = new Zend_View (array ('basePath' = > $baseDir)); return $this- > view;} / * * Render a view * * Renders a view. By default, views are found in the viewscript path as * / .phtml. You may change the script suffix by * resetting {@ link $viewSuffix}. You may omit the controller directory * prefix by specifying boolean true for $noController. * By default, the rendered contents are appended to the response. You may * specify the named body content segment to set by specifying a $name. * * @ see Zend_Controller_Response_Abstract::appendBody () * @ param string | null $action Defaults to action registered in request object * @ param string | null $name Response object named path segment to use; defaults to null * @ param bool $noController Defaults to false I.e. Use controller name as subdir in which to search for viewscript * @ return void * / public function render ($action = null, $name = null, $noController = false) {if (! $this- > getInvokeArg ('noViewRenderer') & & $this- > _ helper- > hasHelper (' viewRenderer')) {return $this- > _ helper- > viewRenderer- > render ($action, $name, $noController);} $view = $this- > initView (); $script = $this- > getViewScript ($action, $noController) $this- > getResponse ()-> appendBody ($view- > render ($script), $name);} / * * Render a given viewscript * * Similar to {@ link render ()}, this method renders a viewscript. Unlike render (), * however, it does not autodetermine the viewscript via {@ link getViewScript ()}, * but instead renders the script passed to it. Use this if you know the * exact viewscript name and path you wish to use, or if using paths that do not * conform to the spec defined with getViewScript (). * By default, the rendered contents are appended to the response. You may * specify the named body content segment to set by specifying a $name. * * @ param string $script * @ param string $name * @ return void * / public function renderScript ($script, $name = null) {if (! $this- > getInvokeArg ('noViewRenderer') & & $this- > _ helper- > hasHelper (' viewRenderer')) {return $this- > _ helper- > viewRenderer- > renderScript ($script, $name);} $view = $this- > initView (); $this- > getResponse ()-> appendBody ($view- > render ($script), $name);}

Zend_View.php class

The above is all the content of the article "how to use Zend_View, the View component of Zend Framework". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report