0

I'm starting to get into Zend Framework 2, and one of the things that I'd like to do is create an intercept that strips all the tabs out of template files before the view vars are inserted into them.

I gather that I'd have to implement my own render strategy, but I can't quite figure out how to replace the default one (phprenderer). Is it just a matter of setting a strategy of the same name with a higher value then the default one?

4

1 回答 1

0

For reference, I've solved the issue by adding a Filter

namespace Application\Filter;

use Zend\Filter\FilterInterface;

class FilterMinifyHTML implements FilterInterface {

    public function filter($value) {

        return \Minify_HTML::minify($value, array(
            'cssMinifier' => array('Minify_CSS', 'minify'),
            'jsMinifier'  => array('JSMin', 'minify'),
        ));

    }

}

And then applied the filter as such (within PhpRenderStrategy.php)

/**
 * Constructor
 *
 * @param  PhpRenderer $renderer
 */
public function __construct(PhpRenderer $renderer) {
    $this->renderer = $renderer;
    $filterChain = new FilterChain();
    $filterChain->attach(new FilterMinifyHTML());
    $this->renderer->setFilterChain($filterChain);
}
于 2013-04-13T18:02:50.343 回答