我目前正在 PHP 5.4.4 上使用 Zend Framework 2 beta 开发个人 web 应用程序以用于自学目的。
我想知道是否可以在 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)