Ala*_*orm 19
Magento使用响应对象发送所有输出.
将所有输出添加到此对象,然后sendResponse调用其方法.
如果要更改输出,请为http_response_send_before事件设置侦听器
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
然后在你的观察者中你可以得到并设置身体
class Packagename_Modulename_Model_Observer
{
public function alterOutput($observer)
{
$response = $observer->getResponse();
$html = $response->getBody();
//modify html here
$response->setBody($html);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您有兴趣,可以在sendResponse以下类的方法中调用此事件
app/code/core/Mage/Core/Controller/Response/Http.php
Run Code Online (Sandbox Code Playgroud)
并且输出本身是在sendResponse和outputBody方法中发送的
lib/Zend/Controller/Response/Abstract.php
Run Code Online (Sandbox Code Playgroud)
理想情况下,您希望在缓存输出之前执行缩小以避免过于频繁地执行此操作.我能想到的最好的地方是覆盖Mage_Page_Block_Html并将以下函数添加到新类中:
protected function _toHtml()
{
$html = parent::_toHtml();
// MINIFY CONTENTS OF $html HERE
return $html;
}
Run Code Online (Sandbox Code Playgroud)
这样,它对整个页面执行一次操作,然后Magento以通常的方式缓存返回的值.它不是单独执行每个块,可能效率较低.
| 归档时间: |
|
| 查看次数: |
4533 次 |
| 最近记录: |