$ hook [' display_override'] []无法在CodeIgniter中工作1.72

时间:2016-10-10 07:58:32

标签: php html codeigniter optimization

CodeIgniter 1.7.2版本,我很奇怪,hook ==> display_override不起作用。

我测试了其他的钩子==> pre_controller,post_controller工作正常,但只有这个钩子的问题==> display_override不起作用。

我测试了这个钩子,在不调用的钩子的回调函数中插入die()。 (回调函数输出())

我正在进行HTML优化,如下所示。请任何想法

目录:

1) 应用/配置/ config.php中

$config['enable_hooks'] = TRUE;

======================================== 2) 应用/配置/ hooks.php

$hook['display_override'][] = array(
    'class' => 'Minifyhtml',
    'function' => 'output',
    'filename' => 'Minifyhtml.php',
    'filepath' => 'hooks',
    'params' => array()
);

=============================================

3) 应用/钩/ 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 =& 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 [\t\r\n\f\v] 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 个答案:

答案 0 :(得分:0)

现在是使用CodeIgniter 3版本的时候了。

在你的例子中或许存在额外的括号[] 试试这段代码:

for /R