问题描述
我想缩小所有html输出。
Magento使用响应对象来发送所有输出。
所有输出都添加到此对象中,调用 sendResponse
方法。
如果您想要更改输出,请为 http_response_send_before
事件设置一个侦听器
<! - 在你的模块的config.xml中 - >
< http_response_send_before>
<观察者>
< unique_name>
< type>单身< / type>
< class> group / observer< / class>
< method> alterOutput< / method>
< / unique_name>
< /观察员>
< / http_response_send_before>
然后在您的观察者中您可以获取并设置身体
class Packagename_Modulename_Model_Observer
{
public function alterOutput($ observer)
{
$ response = $ observer->的GetResponse();
$ html = $ response-> getBody();
//在这里修改html
$ response-> setBody($ html);
code
$ b 如果你有兴趣,以下类的 sendResponse
方法
app / code / core / Mage / Core / Controller / Response / Http.php
并且输出本身以 sendResponse
和 outputBody
的方法
lib / Zend / Controller / Response / Abstract.php
Is there any file in magento where all html will be output?
I want to minify all html output.
解决方案 Magento uses a response object to send all output.
All output is added to this object, and then its sendResponse
method is called.
If you want to alter the output, setup a listener for the http_response_send_before
event
<!-- in your module's config.xml -->
<http_response_send_before>
<observers>
<unique_name>
<type>singleton</type>
<class>group/observer</class>
<method>alterOutput</method>
</unique_name>
</observers>
</http_response_send_before>
And then in your observer you may get and set the body
class Packagename_Modulename_Model_Observer
{
public function alterOutput($observer)
{
$response = $observer->getResponse();
$html = $response->getBody();
//modify html here
$response->setBody($html);
}
}
If you're interested, this event is called in the sendResponse
method of the following class
app/code/core/Mage/Core/Controller/Response/Http.php
and the output itself is sent in the sendResponse
and outputBody
methods of
lib/Zend/Controller/Response/Abstract.php
这篇关于Magento:缩小HTML输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!