2016-10-10 31 views
0

CodeIgniter 1.7.2版本和我很奇怪,鉤==> display_override不工作。

我測試了其他的鉤==> pre_controller,post_controller是工作知府,但只有問題與此鉤==> display_override不工作。

我測試了這個鉤子,以便在不調用鉤子的回調函數中插入die()。 (回調函數輸出())

我正在進行如下HTML優化。請任何想法

目錄: -

1) 的application/config/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(); 
    } 
} 
?> 

請幫助我。

回答

0

現在是時候使用CodeIgniter 3版本了。

在你也許爲例存在額外的括號[] 試試這個代碼:

$hook['display_override'] = ...