Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Zend View Filter?

What is a Zend View Filter? I see them mentioned in the ZF1 documentation, http://framework.zend.com/manual/1.12/en/zend.view.introduction.html, and in the Zend_View code, but I can't find an explanation for them.

Perhaps it is to support other templating systems which have filters? In that case, what do the filters do in these templating systems?

Thanks!

like image 349
DatsunBing Avatar asked Apr 04 '13 04:04

DatsunBing


1 Answers

here is an example of a Zend View Filter:

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

It filters found mailto links and obfuscates them.

A Zend View Filter does something on an already rendered phtml file (= html code) before it is send to the client.

It's a Zend_Filter that can be used on the Zend View output.

Here is another example with code from:

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

The filter class (filters whitespaces from html = less code to send):

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

And then adding the filter to the view:

/**
 * Add Output filters to View
 *
 * @return void
 */
protected function _initViewFilter()
{
    $view = $this->getResource('view');
    $view->addFilterPath('App/View/Filter', 'App_View_Filter_')
        ->addFilter('Minify');
}
like image 108
Lucian Depold Avatar answered Nov 20 '22 07:11

Lucian Depold