[英]How setCredentialTreatment() works in Zend Framework 1.12?
[英]How to minify HTML output in Zend Framework 1.12
按照此處提到的過程https://www.tkcodez.info/minify-html-output-via-php-code/ 。 我試圖將一個腳本注入我的布局文件之一,如下所示:
// Layout.phtml
<?php
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php /*?><meta name="verify-v1" content="zXRjEY50qXN7Oxbt0tAIDegKmUk5nG32qLmAzMuZSw0=" /><?php */?>
<meta name="google-site-verification" content="J-w0iienSxG8y23RN-NYZ0oh4y9YBygvb-ealpBmBi0" />
<?php
$controllerName = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
$popupsessionTutor = new Zend_Session_Namespace('Popup_Session_Tutor');
$popupsessionCenter = new Zend_Session_Namespace('Popup_Session_Center');
?>
---- rest of the phtml file -----
但是找不到我的HTML視圖源。 我還需要做什么?
由於您使用的是ZF1並假定MVC,並且您發布的是視圖腳本,因此您可以編寫一個控制器插件,該插件定義一個dispatchLoopShutdown
方法,該方法可以進行所需的響應修改。
<?php
class My_Controller_Plugin_Sanitize extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$body = preg_replace($search, $replace, $this->getResponse()->getBody());
$this->getResponse()->setBody($body);
unset($body);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.