是否可以在Zend Framework 2中输出hmat(清理)输出?现在它输出时没有正确的换行符和标签。
我知道这个方法:
$dom = new DOMDocument();
$dom->preserveWhiteSpace = FALSE;
$dom->loadHTML($html);
$dom->formatOutput = TRUE;
echo $dom->saveHTML();
但我不明白我在哪里拦截ZF2中的输出。任何帮助将不胜感激。
现在所有的html代码都是在布局中创建的。
答案 0 :(得分:0)
你可以将一个监听器附加到“完成”mvc-event(http://framework.zend.com/manual/2.1/en/modules/zend.mvc.mvc-event.html)并让它在发送之前清理响应。
在你的应用程序的module.php中,在Module类中添加如下内容。
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_FINISH, function(MvcEvent $e){
$content = $e->getResponse()->getContent();
$cleancontent = clean_up_html(content); // clean_up_html() not provided
$e->getResponse()->setContent($cleancontent);
});
}