亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發(fā) > PHP > 正文

Zend Framework教程之視圖組件Zend_View用法詳解

2024-05-04 23:43:35
字體:
供稿:網(wǎng)友
這篇文章主要介紹了Zend Framework教程之視圖組件Zend_View用法,較為詳細的分析了試圖組件Zend_View原理并結(jié)合實例形式分析了Zend_View的使用技巧,需要的朋友可以參考下
 

本文實例講述了Zend Framework教程之視圖組件Zend_View用法。分享給大家供大家參考,具體如下:

Zend_View是Zend Framework的視圖組件,MVC中的視圖層。 Zend_View也是應(yīng)用的直接對用戶展示的頁面。這里介紹一下Zend_View的實現(xiàn)類,以及如何和Controller結(jié)合在一起的。

View的實現(xiàn)

Zend_View的實現(xiàn)主要是通過如下目錄的類實現(xiàn):

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類中,

/**   * 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 view script path as   * <controller>/<action>.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_View.php類

<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category  Zend * @package  Zend_View * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) * @license  http://framework.zend.com/license/new-bsd   New BSD License * @version  $Id: View.php 23775 2011-03-01 17:25:24Z ralph $ *//** * Abstract master class for extension. */require_once 'Zend/View/Abstract.php';/** * Concrete class for handling view scripts. * * @category  Zend * @package  Zend_View * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) * @license  http://framework.zend.com/license/new-bsd   New BSD License */class Zend_View extends Zend_View_Abstract{  /**   * Whether or not to use streams to mimic short tags   * @var bool   */  private $_useViewStream = false;  /**   * Whether or not to use stream wrapper if short_open_tag is false   * @var bool   */  private $_useStreamWrapper = false;  /**   * Constructor   *   * Register Zend_View_Stream stream wrapper if short tags are disabled.   *   * @param array $config   * @return void   */  public function __construct($config = array())  {    $this->_useViewStream = (bool) ini_get('short_open_tag') ? false : true;    if ($this->_useViewStream) {      if (!in_array('zend.view', stream_get_wrappers())) {        require_once 'Zend/View/Stream.php';        stream_wrapper_register('zend.view', 'Zend_View_Stream');      }    }    if (array_key_exists('useStreamWrapper', $config)) {      $this->setUseStreamWrapper($config['useStreamWrapper']);    }    parent::__construct($config);  }  /**   * Set flag indicating if stream wrapper should be used if short_open_tag is off   *   * @param bool $flag   * @return Zend_View   */  public function setUseStreamWrapper($flag)  {    $this->_useStreamWrapper = (bool) $flag;    return $this;  }  /**   * Should the stream wrapper be used if short_open_tag is off?   *   * @return bool   */  public function useStreamWrapper()  {    return $this->_useStreamWrapper;  }  /**   * Includes the view script in a scope with only public $this variables.   *   * @param string The view script to execute.   */  protected function _run()  {    if ($this->_useViewStream && $this->useStreamWrapper()) {      include 'zend.view://' . func_get_arg(0);    } else {      include func_get_arg(0);    }  }}

默認情況會自動通過Controller會通過render方法來實例化Zend_View, 然后rener到對應(yīng)的視圖文件中。當然可以自己實例化Zend_View,然后使用。

action默認指向的文件是和action的名稱相同,如果要指定視圖文件,可以通過$this->render的相關(guān)方法指定.也可以通過addScriptPath和setScriptPath設(shè)置視圖文件的目錄。

例如

$view = new Zend_View();$view->addScriptPath('/www/app/myviews');$view->addScriptPath('/www/app/viewscomm');// 如果調(diào)用 $view->render('example.php'), Zend_View 將// 首先查找 "/www/app/myviews/example.php", 找不到再找"/www/app/viewscomm/example.php", 如果還找不到,最后查找當前目錄下/的"example.php".

Zend_View的常用方法

public function __construct($config = array())

構(gòu)造函數(shù)參數(shù)

例如

array( 'escape' => array(), 'encoding' => array(),);

常見key:

escape、encoding、basePath、basePathPrefix、scriptPath、helperPath、 helperPathPrefix、filterPath、filterPathPrefix、filter
public function getEngine() Return the template engine object

public function init()初始化函數(shù)

/*** Given a base path, sets the script, helper, and filter paths relative to it** Assumes a directory structure of:* <code>* basePath/*   scripts/*   helpers/*   filters/* </code>** @param string $path* @param string $prefix Prefix to use for helper and filter paths* @return Zend_View_Abstract*/public function setBasePath($path, $classPrefix = 'Zend_View')/*** Given a base path, add script, helper, and filter paths relative to it** Assumes a directory structure of:* <code>* basePath/*   scripts/*   helpers/*   filters/* </code>** @param string $path* @param string $prefix Prefix to use for helper and filter paths* @return Zend_View_Abstract*/public function addBasePath($path, $classPrefix = 'Zend_View')public function addScriptPath($path)Adds to the stack of view script paths in LIFO order.public function setScriptPath($path) Resets the stack of view script paths.public function getScriptPath($name)Return full path to a view script specified by $namepublic function getScriptPaths()Returns an array of all currently set script pathspublic function addHelperPath($path, $classPrefix = 'Zend_View_Helper_')Adds to the stack of helper paths in LIFO order.public function setHelperPath($path, $classPrefix = 'Zend_View_Helper_')Resets the stack of helper paths.public function getHelperPath($name) Get full path to a helper class file specified by $namepublic function getHelperPaths()Returns an array of all currently set helper pathspublic function getHelper($name) Get a helper by namepublic function getHelpers()Get array of all active helperspublic function getAllPaths() Return associative array of path types => pathspublic function setEscape($spec)/*** Assigns variables to the view script via differing strategies.** Zend_View::assign('name', $value) assigns a variable called 'name'* with the corresponding $value.** Zend_View::assign($array) assigns the array keys as variable* names (with the corresponding array values).** @see  __set()* @param string|array The assignment strategy to use.* @param mixed (Optional) If assigning a named variable, use this* as the value.* @return Zend_View_Abstract Fluent interface* @throws Zend_View_Exception if $spec is neither a string nor an array,* or if an attempt to set a private or protected member is detected*/public function assign($spec, $value = null)

在controller的action可以通過assign傳遞參數(shù)到視圖腳本。

例如

$this->view->assign('roles', $roles);$this->view->assign('num', $num);$this->view->assign('a', $a);

或者也可以用

$this->view->roles=$roles;$this->view->a=$a;public function render($name) Processes a view script and returns the output.public function escape($var):Escapes a value for output in a view script.public function setEncoding($encoding) Set encoding to use with htmlentities() and htmlspecialchars()public function getEncoding() :Return current escape encoding

視圖腳本文件中的常見用法

獲取傳遞過來的值

$this->roles

使用一些常見的助手方法:

$this->baseUrl();$this->url();$this->paginationControl();$this->partial()

視圖常見用法舉例

在bootstrap初始化view或者controller的init文件中

/** * Initialize the common view helper */protected function _initViewHelper(){  $boot=$this->bootstrap('View');  $view = $boot->getResource('View');        $view->setHelperPath('Sql/View/Helper', 'Sql_View_Helper');}

action中

/** * * @return void */public function listAction(){  $this->view->assign('data', $data);}

視圖文件

list.phtml

<?php foreach ($this->data as $item) : ?><tr style="height: 19px;">    <td class="datagrid-cell"><?php echo($item->item1);?></td></tr><?php endforeach; ?>
 


注:相關(guān)教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
天堂中文在线资| 国产激情视频网址| 正义之心1992免费观看全集完整版| 欧洲成人一区二区三区| 国产51人人成人人人人爽色哟哟| 久草视频在线免费| av中文字幕一区二区| 日本黄色动态图| 一本色道久久88| 天堂视频在线免费观看| 女同互忝互慰dv毛片观看| 欧美日韩精品在线播放| 久久精品日产第一区二区三区精品版| 欧美色视频在线| 在线观看视频黄色| 日本a口亚洲| 免费观看日批视频| 中文字幕一区二区在线视频| 一区二区三区免费观看| 你懂的国产精品| 香蕉97视频观看在线观看| 日本三区在线观看| 成人免费网站视频| 亚洲国产一区二区三区在线播放| 免费看美剧网站| 福利小视频在线观看| 精品国产依人香蕉在线精品| 国产偷国产偷精品高清尤物| 一区二区三区在线观看免费| 国产成人激情av| 久久久99精品免费观看不卡| 国产一区二区调教| 欧美久久久久久一卡四| 麻豆成人久久精品二区三区小说| 香蕉视频在线观看免费| 欧美日本精品一区二区三区| 丁香花在线影院观看在线播放| av在线免费观看网址| 日本精品一区二区三区高清 久久| 欧美综合在线第二页| 91一区一区三区| 伊人久久国产| 亚洲aaa视频| 日韩电影在线一区二区| 毛片电影在线| 午夜美女久久久久爽久久| 四虎成人影院网址| wwwxxxx国产| 久久国产精品黑丝| 午夜在线视频观看日韩17c| 精品国产乱码一区二区| 久久se精品一区精品二区| 国产另类ts人妖一区二区| 稀缺小u女呦精品呦| 欧美二区三区| 99福利在线| 香蕉97视频观看在线观看| 婷婷丁香花五月天| 午夜视频在线观看一区| 99在线精品视频| 亚洲电影中文字幕在线观看| 亚洲mv大片欧洲mv大片精品| 五月伊人六月| 欧美精选在线| 亚洲性人人天天夜夜摸| 影视亚洲一区二区三区| 精品人妻一区二区乱码| 网站在线观看你懂的| 妺妺窝人体色www看人体| 国产精品xxxxxx| 中文字幕在线观看国产| 亚欧洲精品在线视频免费观看| 国产精品视频网| 狠狠色综合色区| av综合在线观看| 视频在线观看入口黄最新永久免费国产| 天天综合五月天| 在线精品视频小说1| 国产午夜亚洲精品理论片色戒| 91theporn国产在线观看| 日韩欧美高清在线视频| 91理论片午午论夜理片久久| 白浆在线视频| 中文字幕精品视频在线观看| 亚洲伦理精品| 精品手机在线视频| 久久先锋影音av鲁色资源| 欧美日韩国产欧美日美国产精品| 亚洲在线偷拍自拍| 粉嫩久久久久久久极品| 欧美另类中文字幕| 韩国一区二区av| 日韩精品视频无播放器在线看| www.偷拍.com| 天天躁日日躁aaaa视频| 麻豆国产在线播放| 成人免费的视频| 色网站在线看| 女人十八岁毛片| 肉肉视频在线观看| 国产美女自慰在线观看| 欧美国产视频日韩| 成人免费一区二区三区| 欧美日韩国产成人高清视频| 日韩精品极品视频免费观看| 最新国产精品久久精品| 日本一区二区视频在线| 亚洲精品www久久久久久| 伊人久久综合网另类网站| 欧美精品网站| 亚洲AV午夜精品| 99精品人妻少妇一区二区| 精品国产乱码久久久久久鸭王1| 青青青青国产视频| 久久精品凹凸全集| 操人视频免费看| 污污免费在线观看| 精品动漫3d一区二区三区免费| 亚洲乱码日产精品bd在线观看| 国产精品主播直播| 男人的天堂成人| 白虎精品一区| 免费观看成人在线视频| 亚洲人成电影院在线观看| 成人软件在线观看| 欧美激情图片小说| 先锋影音在线资源站91| 成年人视频大全| 波多野结衣网页| 国产激情二区| 三级av在线播放| 综合分类小说区另类春色亚洲小说欧美| 香蕉视频免费看| 成年人一级黄色片| 免费黄网站观看| 日本高清色图| 国产福利视频一区二区三区| 久久久精品少妇| 日本免费网站视频| 伊人久久久久久久久久久久久| 激情欧美日韩一区二区| 99re视频在线播放| 亚洲精品动漫久久久久| 久久成人精品视频| 午夜精品久久久久久久久久蜜桃| 国产不卡一区二区在线观看| 韩日毛片在线观看| 中文一区在线观看| 日韩亚洲视频在线| 亚洲欧美综合色| 国产精品一品| 777午夜精品免费视频| 日韩三级成人av网| 成人午夜视频一区二区播放| 欧美性猛交xxxx久久久| 亚洲伊人成人网| 亚欧精品一区二区三区| 蜜桃一区av| 尤物视频在线免费观看| 国产成人免费视频一区| 亚洲图片小说在线| 99国产精品久久久久久久成人热| 吉吉日韩欧美| 欧美日韩一区二区在线观看| 成人黄色av网站在线| 天天躁日日躁狠狠躁伊人| 婷婷福利视频导航| 超碰porn在线| 最近更新的2019中文字幕| 老司机凹凸av亚洲导航| 一本大道久久a久久综合| 免费av片风间由美在线| 亚洲在线黄色| 中文字幕777| 精品日本一线二线三线不卡| 亚洲不卡在线视频| 成年人免费av| 114国产精品久久免费观看| 超碰cao国产精品一区二区| 在线资源免费观看| 久草中文视频| av中文一区二区三区| 久久精品99国产精品日本| 久久亚洲精选| 亚洲成人第一网站| 韩国自拍一区| 欧美日韩在线看| 欧美激情第1页| 久久久久亚洲精品成人网小说| 中文字幕在线亚洲精品| 国产精品福利无圣光在线一区| 免费观看的av网站| 色老头视频在线观看| 欧美电影免费网站| 久久成人精品无人区| 美女脱光衣服与内衣内裤一区二区三区四区| 国产精品一区二区资源| 中文字幕第88页| gogogo免费视频观看亚洲一| 欧美综合在线视频观看| 午夜在线免费观看视频| 欧美日韩国产三级| 登山的目的在线| 欧美三级成人观看| 欧美成人高清视频在线观看| 亚洲精品免费在线观看视频| 黄网在线观看| 91精品国产综合久久香蕉的特点| 五月天激情开心网| 综合色天天鬼久久鬼色| 国产一区二区三区日韩欧美| 色棕色天天综合网| 久久久久久九九| 在线观看日韩精品| 亚洲五月激情网| 国产精一品亚洲二区在线视频| 婷婷五月色综合香五月| 欧美日韩国产一级| 国产综合久久久久久久久久久久| 丝袜美腿精品国产二区| 欧美一级黄色片视频| 欧美日韩午夜电影网| www.青青青| 狠狠久久亚洲欧美| 濑亚美莉一二区在线视频| 国产精品视频内| 国内在线高清免费视频| 亚洲精品国产品国语在线| 欧美最猛性xxxxx直播| 毛片手机在线观看| 伊人久久大香线蕉成人综合网| 黄色激情在线观看| 日本精品视频在线播放| 在线观看中文| 国产成人精品亚洲日本在线观看| 四虎成人精品一区二区免费网站| 亚洲熟女www一区二区三区| 日韩黄色片在线| 先锋影音亚洲资源| 一本色道久久综合亚洲精品酒店| 蜜臀av性久久久久av蜜臀妖精| 欧美日韩1区2区| 日韩在线网址| 91丨九色丨国产| 中文字幕a在线观看| 欧美性一区二区| 中文字幕资源在线观看| 国产在线观看精品一区二区三区| 国产对白叫床清晰在线播放| 国产精品美女久久久久久2018| 国产一区二区黑人欧美xxxx| 69夜色精品国产69乱| 男人女人靠逼视频| 91在线观看免费高清完整版在线观看| 国产又黄又粗又猛又爽| 亚洲精品免费av| 先锋影音在av资源看片| 国产wwww| 精品久久国产视频| 午夜精品免费看| 久久久久九九视频| 99热在线成人| 成人黄色在线免费| 久久午夜精品一区二区| 国产精品久久久久久久精| 美女av在线免费观看| 日本免费资源| 玖草视频在线观看| 国产日韩精品一区二区三区在线| 久草在线资源网| 激情久久久久| 中文字幕av网| 91电影在线播放| 亚洲黑丝一区二区| 天天伊人狠狠| 99re在线视频这里只有精品| 国产精品国产三级国产普通话99| 亚洲天堂中文字幕| 中文字幕av免费观看| 精品国产91乱码一区二区三区四区| 九色在线播放| www.成人精品免费网站青椒| 作爱视频免费观看视频在线播放激情网| 国产精品一区二区久久国产| 痴汉一区二区三区| www.夜夜操| 久久人妻少妇嫩草av无码专区| 欧美成人一区二区在线| 夜夜摸视频网| 岛国视频一区| 国产精品成人久久久久| 色呦呦在线免费观看| 久久综合偷偷噜噜噜色| 国产精品丝袜xxxxxxx| 国产va在线观看| 欧美成年人视频网站| 韩国成人av| 91九色porny在线| 亚洲乱码国产乱码精品精的特点| jizz.日本| 五月天亚洲婷婷| 亚洲天堂电影网| 超碰97久久国产精品牛牛| 日韩在线观看免费全集电视剧网站| 欧美成人精品一级| 国产视频一二三区| 国产av第一区| 成人av一区二区三区在线观看| 欧美精品videossex变态| jizz18女人高潮| 日韩中文字幕在线一区| 国产黑人绿帽在线第一区| 国产高清视频免费在线观看| 国产成人精品无码免费看夜聊软件| 97免费在线视频| 国产一区 二区 三区一级| 亚洲 欧美 变态 另类 综合| 中文字幕在线字幕中文| 国产在线观看不卡一区二区三区| 中文字幕无码不卡免费视频| 国产黄色免费在线观看| 国偷自产av一区二区三区小尤奈| 五月天丁香婷| 色偷偷综合社区| 成人动漫在线播放| 精品不卡一区| 麻豆传媒在线免费看| 在线综合亚洲欧美在线视频|