在模块中的module.php文件中加如下代码
|
public function onBootstrap($e) { //页面压缩性能设置 if(defined('DBSHOP_ADMIN_COMPRESS') and defined('DBSHOP_FRONT_COMPRESS') and (DBSHOP_ADMIN_COMPRESS == 'true' or DBSHOP_FRONT_COMPRESS == 'true')) { $app->getEventManager()->attach("finish", array($this, "compressOutput"), 100); } } |
然后在该文件中加入compressOutput方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public function compressOutput($e) { $matches = $e->getRouteMatch(); if(!$matches) return; $controller = $matches->getParam('controller'); //前台压缩处理开启 if(DBSHOP_ADMIN_COMPRESS == 'false' and DBSHOP_FRONT_COMPRESS == 'true') { if (false === strpos($controller, __NAMESPACE__)) return; } //后台压缩处理开启 if(DBSHOP_ADMIN_COMPRESS == 'true' and DBSHOP_FRONT_COMPRESS == 'false') { if (false !== strpos($controller, __NAMESPACE__)) return; } $response = $e->getResponse(); $content = $response->getBody(); if(@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) { header('Content-Encoding: gzip'); $content = gzencode($content, 9); } $response->setContent($content); } |
这是DBShop程序的处理方式,没有写的多么的复杂,简单易懂就可以了。