2013-04-04 79 views

回答

7

這裏是一個Zend視圖篩選的例子:

http://dev.bigace.org/api/3.0/Bigace_Zend/View_Filter/Bigace_Zend_View_Filter_ObfuscateMailto.html

它找到過濾mailto鏈接和混淆他們。

Zend View Filter會在發送給客戶端之前對已經呈現的phtml文件(= html代碼)進行某些操作。

這是一個可以在Zend View輸出中使用的Zend_Filter。

這裏是與來自碼另一個例子:

http://www.phpgangsta.de/zend_view-output-filter-whitespaces-aus-html-entfernen

濾波器類(過濾器空格從HTML =較少的代碼發送):

<?php 
class App_View_Filter_Minify implements Zend_Filter_Interface 
{ 
    public function filter($string) 
    { 
     return preg_replace(
      array('/>\s+/', '/\s+</', '/[\r\n]+/'), 
      array('>', '<', ' '), 
      $string 
     ); 
    } 
} 

,然後加入過濾器的位置查看:

/** 
* Add Output filters to View 
* 
* @return void 
*/ 
protected function _initViewFilter() 
{ 
    $view = $this->getResource('view'); 
    $view->addFilterPath('App/View/Filter', 'App_View_Filter_') 
     ->addFilter('Minify'); 
}