php - 压缩 zend framework 2 的 html 输出

标签 php zend-framework2 output-buffering html-manipulation

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

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

我怎样才能在 ZF2 中实现这个结果?

最佳答案

是的,您可以:

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

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);

}

关于php - 压缩 zend framework 2 的 html 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11309904/

相关文章:

php - 任何有效的 php 调试器,PDT?

PHP:如何从 JSON 数组中获取属性?

php - mysql通过不返回左表中的所有结果来左连接和分组

python - python中打印函数的错误?

php - 输出缓冲和 FirePHP 错误

Phpunit,测试代码或测试代码没有(仅)关闭自己的输出缓冲区

php - 从控制台运行 Zend Framework 2 操作不起作用

model-view-controller - Zend Framework 2 : Modify details of layout. Controller 中的 pthml

zend-framework2 - ZF2 : When would you use autoload_classmap. php

php - ZF2 - 使用导航 View 助手的多个导航菜单