PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Zend Framework教程之视图组件Zend_View用法详解大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了Zend Framework教程之视图组件Zend_View用法分享给大家供大家参,具体如下:

Zend_View是Zend Framework的视图组件,MVC中的视图层。 Zend_View也是应用的直接对用户展示的页面。这里介绍一下Zend_View的实现类,以及如何和Controller结合在一起的。

View的实现

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_View和Zend_Controller的整合

主要在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,请注明来意。