我正在使用CI开发网站。一般来说,我们编写的HTML代码如下:
<header>
<div class="banner">
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>Site Title</h1>
<h2>Sub Totle</h2>
<div class="logo"></div>
</div>
</div>
</div>
</div>
</header>
之后,我们使用CI加载视图,如:
$this->load->view('view');
现在我的问题是,如何加载这个视图,并替换views/view.php文件中的所有选项卡和新行,如下图所示?
<header><div class="banner"><div class="container"><div class="row"><div class="col-xs-12 ac"><h1>Site Title</h1><h2>Sub Totle</h2><div class="logo"></div></div></div></div></div></header>
总之,如何丑化CodeIgniter视图的HTML代码?
提前谢谢。
转到system/application/config/config.php
并检查挂钩是否启用:
$config['enable_hooks'] = TRUE;
在system/application/config/hooks.php
:中声明新钩子
// compress output
$hook['display_override'][] = array(
'class' => '',
'function' => 'compress',
'filename' => 'compress.php',
'filepath' => 'hooks'
);
在system/application/hooks/compress.php
:中添加钩子
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function compress()
{
$CI =& get_instance();
$buffer = $CI->output->get_output();
$search = array(
'/'n/', // replace end of line by a space
'/'>[^'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);
$CI->output->set_output($buffer);
$CI->output->_display();
}
/* End of file compress.php */
/* Location: ./system/application/hooks/compress.php */
来源:http://jeromejaglale.com/doc/php/codeigniter_compress_html
或者,您可以从以下位置轻松安装此挂钩:https://github.com/johngerome/CodeIgniter-Minifyhtml-hooks#codeigniter-minimyhtml挂钩