#php #html #codeigniter #optimization
#php #HTML #codeigniter #оптимизация
Вопрос:
Версия CodeIgniter 1.7.2, и мне очень странно, что hook ==> display_override не работает.
Я протестировал другие перехваты ==> pre_controller, post_controller, которые работали нормально, но единственная проблема с этим перехватом ==> display_override не работает.
Я протестировал этот хук, чтобы вставить die() в функцию обратного вызова хука, которая не вызывается. (функция обратного вызова output() )
Я работаю над оптимизацией HTML, как показано ниже. пожалуйста, есть идеи
Каталог:
1) application/config/config.php
$config['enable_hooks'] = TRUE;
========================================
2)
application/config/hooks.php
$hook['display_override'][] = array(
'class' => 'Minifyhtml',
'function' => 'output',
'filename' => 'Minifyhtml.php',
'filepath' => 'hooks',
'params' => array()
);
=============================================
3) application/hooks/Minifyhtml.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Minifyhtml Class
* Will Minify the HTML. Reducing network latency, enhancing compression, and faster browser loading and execution.
*
* @category Output
* @author John Gerome
* @link https://github.com/johngerome/CodeIgniter-Minifyhtml-hooks
*/
class Minifyhtml {
/**
* Responsible for sending final output to browser
*/
function output()
{
$CI =amp; get_instance();
$buffer = $CI->output->get_output();
$re = '% # Collapse ws everywhere but in blacklisted elements.
(?> # Match all whitespans other than single space.
[^S ]s* # Either one [trnfv] and zero or more ws,
| s{2,} # or two or more consecutive-any-whitespace.
) # Note: The remaining regex consumes no text at all...
(?= # Ensure we are not in a blacklist tag.
(?: # Begin (unnecessary) group.
(?: # Zero or more of...
[^<] # Either one or more non-"<"
| < # or a < starting a non-blacklist tag.
(?!/?(?:textarea|pre)b)
)* # (This could be "unroll-the-loop"ified.)
) # End (unnecessary) group.
(?: # Begin alternation group.
< # Either a blacklist start tag.
(?>textarea|pre)b
| z # or end of file.
) # End alternation group.
) # If we made it here, we are not in a blacklist tag.
%ix';
$buffer = preg_replace($re, " ", $buffer);
$CI->output->set_output($buffer);
$CI->output->_display();
}
}
?>
Ответ №1:
Самое время использовать версию CodeIgniter 3.
В вашем примере, возможно, существуют дополнительные скобки [] Попробуйте этот код:
$hook['display_override'] = ...