压缩来自 Zend 框架 2 的 html 输出 [英] Compress html output from zend framework 2

查看:21
本文介绍了压缩来自 Zend 框架 2 的 html 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 PHP 5.4.4 上使用 Zend Framework 2 beta 来开发个人网络应用程序以用于自学目的.

I'm currently using Zend Framework 2 beta for on PHP 5.4.4 to develop a personal webapp for self-study purpose.

我想知道是否可以在发送到浏览器之前截取 html 输出,以便通过删除所有不必要的空格来缩小它.

I was wondering if it is possible to intercept the html output just before it is sent to the browser in order to minify it by removing all unnecessary white spaces.

我怎样才能在 ZF2 中达到这个结果?

How could I achieve this result in ZF2?

推荐答案

是的,您可以:

在 Model.php 上创建一个将在完成时触发的事件

On Modle.php create an event that will trigger on finish

public function onBootstrap(Event $e)
{
    $app = $e->getTarget();
    $app->getEventManager()->attach('finish', array($this, 'doSomething'), 100);
}


public function doSomething ($e)
{
    $response = $e->getResponse();
    $content = $response->getBody();
    // do stuff here
    $response->setContent($content);

}

这篇关于压缩来自 Zend 框架 2 的 html 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆