Codeigniter 生成静态页面
使用CI来生成静态页面,其实很简单,就像论坛里面说的那样,读出页面中的数据,再写入html文件中,最后显示这个html文件就行了,好吧,上码。
[php]
class MY_Loader extends CI_Loader {
public function m_view($view, $vars = array(), $return = FALSE){
return $this->_m_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
protected function _m_ci_load($_ci_data){
.....
$_ci_html_file=($_ci_ext==='')? $_ci_view.".html" : $_ci_view;//这,生成静态页面的文件名
foreach ($this->_ci_view_paths as $_ci_view_file => $cascade){
if (file_exists($_ci_view_file.$_ci_file)){
$_ci_path = $_ci_view_file.$_ci_file;
$_ci_html_path=$_ci_view_file.$_ci_html_file;//生成静态页面的路径
$file_exists = TRUE;
break;
}
......
}
}
.......
//在这
if(config_item("html")===TRUE){//是否开启生成静态页面
$_html_file=@fopen($_ci_html_path,'r');//创建.html文件
$buffer = ob_get_contents();
@ob_end_clean();
if(!$_html_file||(@filesize($_ci_html_path)!=strlen($buffer))){ //如果文件不存在或文件已更变
$_html_file=@fopen($_ci_html_path,'w');
flock($_html_file, LOCK_EX);
fwrite($_html_file, $buffer);
flock($_html_file, LOCK_UN);
fclose($_html_file);
}
//echo(filesize($_ci_html_path)."-".strlen($buffer));
include($_ci_html_path);
}
......
}
}
class MY_Loader extends CI_Loader {
public function m_view($view, $vars = array(), $return = FALSE){
return $this->_m_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
protected function _m_ci_load($_ci_data){
.....
$_ci_html_file=($_ci_ext==='')? $_ci_view.".html" : $_ci_view;//这,生成静态页面的文件名
foreach ($this->_ci_view_paths as $_ci_view_file => $cascade){
if (file_exists($_ci_view_file.$_ci_file)){
$_ci_path = $_ci_view_file.$_ci_file;
$_ci_html_path=$_ci_view_file.$_ci_html_file;//生成静态页面的路径
$file_exists = TRUE;
break;
}
......
}
}
.......
//在这
if(config_item("html")===TRUE){//是否开启生成静态页面
$_html_file=@fopen($_ci_html_path,'r');//创建.html文件
$buffer = ob_get_contents();
@ob_end_clean();
if(!$_html_file||(@filesize($_ci_html_path)!=strlen($buffer))){ //如果文件不存在或文件已更变
$_html_file=@fopen($_ci_html_path,'w');
flock($_html_file, LOCK_EX);
fwrite($_html_file, $buffer);
flock($_html_file, LOCK_UN);
fclose($_html_file);
}
//echo(filesize($_ci_html_path)."-".strlen($buffer));
include($_ci_html_path);
}
......
}
}调用
[html]
$this->load->m_view('login',$datas);
$this->load->m_view('login',$datas);
是否生成HTML文件
$config["html"] = TRUE;
全部代码如下
[php]
class MY_Loader extends CI_Loader {
public function m_view($view, $vars = array(), $return = FALSE){
return $this->_m_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
protected function _m_ci_load($_ci_data){
// Set the default data variables
foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val){
$$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
}
$file_exists = FALSE;
// Set the path to the requested file
if (is_string($_ci_path) && $_ci_path !== ''){
$_ci_x = explode('/', $_ci_path);//使用一个字符串分割另一个字符串
$_ci_file = end($_ci_x);//将数组的内部指针指向最后一个单元
}else{
$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);// 返回文件路径的信息
$_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
$_ci_html_file=($_ci_ext==='')? $_ci_view.".html" : $_ci_view;//这,生成静态页面的文件名
foreach ($this->_ci_view_paths as $_ci_view_file => $cascade){
if (file_exists($_ci_view_file.$_ci_file)){
$_ci_path = $_ci_view_file.$_ci_file;
$_ci_html_path=$_ci_view_file.$_ci_html_file;//生成静态页面的路径
$file_exists = TRUE;
break;
}
if ( ! $cascade){
break;
}
}
}
if ( ! $file_exists && ! file_exists($_ci_path))
{
show_error('Unable to load the requested file: '.$_ci_file);
}
// This allows anything loaded using $this->load (views, files, etc.)
// to become accessible from within the Controller and Model functions.
$_ci_CI =& get_instance();
foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
{
if ( ! isset($this->$_ci_key))
{
$this->$_ci_key =& $_ci_CI->$_ci_key;
}
}
/*
* Extract and cache variables
*
* You can either set variables using the dedicated $this->load->vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/
if (is_array($_ci_vars))
{
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
extract($this->_ci_cached_vars);
/*
* Buffer the output
*
* We buffer the output for two reasons:
* 1. Speed. You get a significant speed boost.
* 2. So that the final rendered template can be post-processed by
* the output class. Why do we need post processing? For one thing,
* in order to show the elapsed page load time. Unless we can
* intercept the content right before it's sent to the browser and
* then stop the timer it won't be accurate.
*/
ob_start();
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE
&& config_item('rewrite_short_tags') === TRUE && function_usable('eval')
)
{
echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('=', '
}
else
{
include($_ci_path); // include() vs include_once() allows for multiple views with the same name
}
log_message('debug', 'File loaded: '.$_ci_path);
// Return the file data if requested
if ($_ci_return === TRUE)
{
$buffer = ob_get_contents();
@ob_end_clean();
return $buffer;
}
//在这
if(config_item("html")===TRUE){//是否开启生成静态页面
$_html_file=@fopen($_ci_html_path,'r');//创建.html文件
$buffer = ob_get_contents();
@ob_end_clean();
if(!$_html_file||(@filesize($_ci_html_path)!=strlen($buffer))){
$_html_file=@fopen($_ci_html_path,'w');
flock($_html_file, LOCK_EX);
fwrite($_html_file, $buffer);
flock($_html_file, LOCK_UN);
fclose($_html_file);
}
//echo(filesize($_ci_html_path)."-".strlen($buffer));
include($_ci_html_path);
}
/*
* Flush the buffer... or buff the flusher?
*
* In order to permit views to be nested within
* other views, we need to flush the content back out whenever
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*/
if (ob_get_level() > $this->_ci_ob_level + 1)
{
ob_end_flush();
}
else
{
$_ci_CI->output->append_output(ob_get_contents());
@ob_end_clean();
}
}
}
class MY_Loader extends CI_Loader {
public function m_view($view, $vars = array(), $return = FALSE){
return $this->_m_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
protected function _m_ci_load($_ci_data){
// Set the default data variables
foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val){
$$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
}
$file_exists = FALSE;
// Set the path to the requested file
if (is_string($_ci_path) && $_ci_path !== ''){
$_ci_x = explode('/', $_ci_path);//使用一个字符串分割另一个字符串
$_ci_file = end($_ci_x);//将数组的内部指针指向最后一个单元
}else{
$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);// 返回文件路径的信息
$_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
$_ci_html_file=($_ci_ext==='')? $_ci_view.".html" : $_ci_view;//这,生成静态页面的文件名
foreach ($this->_ci_view_paths as $_ci_view_file => $cascade){
if (file_exists($_ci_view_file.$_ci_file)){
$_ci_path = $_ci_view_file.$_ci_file;
$_ci_html_path=$_ci_view_file.$_ci_html_file;//生成静态页面的路径
$file_exists = TRUE;
break;
}
if ( ! $cascade){
break;
}
}
}
if ( ! $file_exists && ! file_exists($_ci_path))
{
show_error('Unable to load the requested file: '.$_ci_file);
}
// This allows anything loaded using $this->load (views, files, etc.)
// to become accessible from within the Controller and Model functions.
$_ci_CI =& get_instance();
foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
{
if ( ! isset($this->$_ci_key))
{
$this->$_ci_key =& $_ci_CI->$_ci_key;
}
}
/*
* Extract and cache variables
*
* You can either set variables using the dedicated $this->load->vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/
if (is_array($_ci_vars))
{
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
extract($this->_ci_cached_vars);
/*
* Buffer the output
*
* We buffer the output for two reasons:
* 1. Speed. You get a significant speed boost.
* 2. So that the final rendered template can be post-processed by
* the output class. Why do we need post processing? For one thing,
* in order to show the elapsed page load time. Unless we can
* intercept the content right before it's sent to the browser and
* then stop the timer it won't be accurate.
*/
ob_start();
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE
&& config_item('rewrite_short_tags') === TRUE && function_usable('eval')
)
{
echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('=', '
}
else
{
include($_ci_path); // include() vs include_once() allows for multiple views with the same name
}
log_message('debug', 'File loaded: '.$_ci_path);
// Return the file data if requested
if ($_ci_return === TRUE)
{
$buffer = ob_get_contents();
@ob_end_clean();
return $buffer;
}
//在这
if(config_item("html")===TRUE){//是否开启生成静态页面
$_html_file=@fopen($_ci_html_path,'r');//创建.html文件
$buffer = ob_get_contents();
@ob_end_clean();
if(!$_html_file||(@filesize($_ci_html_path)!=strlen($buffer))){
$_html_file=@fopen($_ci_html_path,'w');
flock($_html_file, LOCK_EX);
fwrite($_html_file, $buffer);
flock($_html_file, LOCK_UN);
fclose($_html_file);
}
//echo(filesize($_ci_html_path)."-".strlen($buffer));
include($_ci_html_path);
}
/*
* Flush the buffer... or buff the flusher?
*
* In order to permit views to be nested within
* other views, we need to flush the content back out whenever
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*/ www.2cto.com
if (ob_get_level() > $this->_ci_ob_level + 1)
{
ob_end_flush();
}
else
{
$_ci_CI->output->append_output(ob_get_contents());
@ob_end_clean();
}
}
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

CrystalDiskMark是一款适用于硬盘的小型HDD基准测试工具,可以快速测量顺序和随机读/写速度。接下来就让小编为大家介绍一下CrystalDiskMark,以及crystaldiskmark如何使用吧~一、CrystalDiskMark介绍CrystalDiskMark是一款广泛使用的磁盘性能测试工具,用于评估机械硬盘和固态硬盘(SSD)的读写速度和随机I/O性能。它是一款免费的Windows应用程序,并提供用户友好的界面和各种测试模式来评估硬盘驱动器性能的不同方面,并被广泛用于硬件评

foobar2000是一款能随时收听音乐资源的软件,各种音乐无损音质带给你,增强版本的音乐播放器,让你得到更全更舒适的音乐体验,它的设计理念是将电脑端的高级音频播放器移植到手机上,提供更加便捷高效的音乐播放体验,界面设计简洁明了易于使用它采用了极简的设计风格,没有过多的装饰和繁琐的操作能够快速上手,同时还支持多种皮肤和主题,根据自己的喜好进行个性化设置,打造专属的音乐播放器支持多种音频格式的播放,它还支持音频增益功能根据自己的听力情况调整音量大小,避免过大的音量对听力造成损害。接下来就让小编为大

在如今云存储已经成为我们日常生活和工作中不可或缺的一部分。百度网盘作为国内领先的云存储服务之一,凭借其强大的存储功能、高效的传输速度以及便捷的操作体验,赢得了广大用户的青睐。而且无论你是想要备份重要文件、分享资料,还是在线观看视频、听取音乐,百度网盘都能满足你的需求。但是很多用户们可能对百度网盘app的具体使用方法还不了解,那么这篇教程就将为大家详细介绍百度网盘app如何使用,还有疑惑的用户们就快来跟着本文详细了解一下吧!百度云网盘怎么用:一、安装首先,下载并安装百度云软件时,请选择自定义安装选

网易邮箱,作为中国网民广泛使用的一种电子邮箱,一直以来以其稳定、高效的服务赢得了用户的信赖。而网易邮箱大师,则是专为手机用户打造的邮箱软件,它极大地简化了邮件的收发流程,让我们的邮件处理变得更加便捷。那么网易邮箱大师该如何使用,具体又有哪些功能呢,下文中本站小编将为大家带来详细的内容介绍,希望能帮助到大家!首先,您可以在手机应用商店搜索并下载网易邮箱大师应用。在应用宝或百度手机助手中搜索“网易邮箱大师”,然后按照提示进行安装即可。下载安装完成后,我们打开网易邮箱账号并进行登录,登录界面如下图所示

MetaMask(中文也叫小狐狸钱包)是一款免费的、广受好评的加密钱包软件。目前,BTCC已支持绑定MetaMask钱包,绑定后可使用MetaMask钱包进行快速登入,储值、买币等,且首次绑定还可获得20USDT体验金。在BTCCMetaMask钱包教学中,我们将详细介绍如何注册和使用MetaMask,以及如何在BTCC绑定并使用小狐狸钱包。MetaMask钱包是什么?MetaMask小狐狸钱包拥有超过3,000万用户,是当今最受欢迎的加密货币钱包之一。它可免费使用,可作为扩充功能安装在网络

Apple在周二推出了iOS17.4更新,为iPhone带来了一系列新功能和修复。这次更新包括了全新的表情符号,同时欧盟用户也能够下载其他应用商店。此外,更新还加强了对iPhone安全性的控制,引入了更多的「失窃设备保护」设置选项,为用户提供更多选择和保障。"iOS17.3首次引入了“失窃设备保护”功能,为用户的敏感资料增加了额外的安全保障。当用户不在家等熟悉地点时,该功能要求用户首次输入生物特征信息,并在一小时后再次输入信息才能访问和更改某些数据,如修改AppleID密码或关闭失窃设备保护功能

如何使用小黑盒cdkey呢?简单来说,您可直接在小黑盒选购Steam平台的游戏,成功购买后将获取一个CDK兑换码。接下来,在Steam商城使用此兑换码即可购得相应游戏。许多朋友可能还不了解如何使用小黑盒cdkey,下面我将为您详细说明其兑换步骤,希望对您有所帮助。小黑盒cdkey如何使用1、先复制购买小黑盒游戏后得到的cdk兑换码。2、随后启动Steam平台。3、点开左上角菜单中的“游戏”选项。4、在新菜单中找到并点击“在Steam上激活产品”。5、在弹出的界面直接点选下一步。6、将小黑盒购买的

小米汽车软件提供远程车控功能,让用户可以通过手机或电脑远程控制车辆,例如开关车辆的门窗、启动引擎、控制车辆的空调和音响等,下文就是这个软件的使用及内容,一起了解下吧。小米汽车app功能及使用方法大全1、小米汽车app在3月25日上线苹果AppStore,现在安卓手机的应用商店中也可以下载了;购车:了解小米汽车核心亮点和技术参数,可预约试驾、配置订购您的小米汽车,支持在线处理提车待办事项。3、社区:了解小米汽车品牌资讯,交流用车体验,分享精彩车生活;4、车控:手机就是遥控器,远程控制,实时安防,轻
