脚本宝典收集整理的这篇文章主要介绍了Zend Framework教程之视图组件Zend_View用法详解,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了Zend Framework教程之视图组件Zend_View用法。分享给大家供大家参考,具体如下:
Zend_View是Zend Framework的视图组件,MVC中的视图层。 Zend_View也是应用的直接对用户展示的页面。这里介绍一下Zend_View的实现类,以及如何和Controller结合在一起的。
Zend_View的实现主要是通过如下目录的类实现:
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
主要在Zend_Controller_Action类中,
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 view script 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 view script * @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 view script * * Similar to {@link render()},this method renders a view script. Unlike render(),* however,it does not autodetermine the view script via {@link getViewScript()},* but instead renders the script passed to it. Use this if you know the * exact view script 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 Framework教程之视图组件Zend_View用法详解全部内容,希望文章能够帮你解决Zend Framework教程之视图组件Zend_View用法详解所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。