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脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

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

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

CrystalDiskMark是一款適用於硬碟的小型HDD基準測試工具,可快速測量順序和隨機讀取/寫入速度。接下來就讓小編為大家介紹一下CrystalDiskMark,以及crystaldiskmark如何使用吧~一、CrystalDiskMark介紹CrystalDiskMark是一款廣泛使用的磁碟效能測試工具,用於評估機械硬碟和固態硬碟(SSD)的讀取和寫入速度和隨機I/O性能。它是一款免費的Windows應用程序,並提供用戶友好的介面和各種測試模式來評估硬碟效能的不同方面,並被廣泛用於硬體評

foobar2000是一款能隨時收聽音樂資源的軟體,各種音樂無損音質帶給你,增強版本的音樂播放器,讓你得到更全更舒適的音樂體驗,它的設計理念是將電腦端的高級音頻播放器移植到手機上,提供更便捷高效的音樂播放體驗,介面設計簡潔明了易於使用它採用了極簡的設計風格,沒有過多的裝飾和繁瑣的操作能夠快速上手,同時還支持多種皮膚和主題,根據自己的喜好進行個性化設置,打造專屬的音樂播放器支援多種音訊格式的播放,它還支援音訊增益功能根據自己的聽力情況調整音量大小,避免過大的音量對聽力造成損害。接下來就讓小編為大

MetaMask(中文也叫小狐狸錢包)是一款免費的、廣受好評的加密錢包軟體。目前,BTCC已支援綁定MetaMask錢包,綁定後可使用MetaMask錢包進行快速登錄,儲值、買幣等,且首次綁定還可獲得20USDT體驗金。在BTCCMetaMask錢包教學中,我們將詳細介紹如何註冊和使用MetaMask,以及如何在BTCC綁定並使用小狐狸錢包。 MetaMask錢包是什麼? MetaMask小狐狸錢包擁有超過3,000萬用戶,是當今最受歡迎的加密貨幣錢包之一。它可免費使用,可作為擴充功能安裝在網絡

網易郵箱,作為中國網友廣泛使用的一種電子郵箱,一直以來以其穩定、高效的服務贏得了用戶的信賴。而網易信箱大師,則是專為手機使用者打造的信箱軟體,它大大簡化了郵件的收發流程,讓我們的郵件處理變得更加便利。那麼網易信箱大師該如何使用,具體又有哪些功能呢,下文中本站小編將為大家帶來詳細的內容介紹,希望能幫助到大家!首先,您可以在手機應用程式商店搜尋並下載網易信箱大師應用程式。在應用寶或百度手機助手中搜尋“網易郵箱大師”,然後按照提示進行安裝即可。下載安裝完成後,我們打開網易郵箱帳號並進行登錄,登入介面如下圖所示

在如今雲端儲存已成為我們日常生活和工作中不可或缺的一部分。百度網盤作為國內領先的雲端儲存服務之一,憑藉其強大的儲存功能、高效的傳輸速度以及便捷的操作體驗,贏得了廣大用戶的青睞。而且無論你是想要備份重要文件、分享資料,還是在線上觀看影片、聽取音樂,百度網盤都能滿足你的需求。但很多用戶可能對百度網盤app的具體使用方法還不了解,那麼這篇教學就將為大家詳細介紹百度網盤app如何使用,還有疑惑的用戶們就快來跟著本文詳細了解一下吧!百度雲網盤怎麼用:一、安裝首先,下載並安裝百度雲軟體時,請選擇自訂安裝選

Apple在周二推出了iOS17.4更新,為iPhone帶來了一系列新功能和修復。這次更新包含了全新的表情符號,同時歐盟用戶也能夠下載其他應用程式商店。此外,更新還加強了對iPhone安全性的控制,引入了更多的「失竊設備保護」設定選項,為用戶提供更多選擇和保障。 "iOS17.3首次引入了「失竊設備保護」功能,為用戶的敏感資料增加了額外的安全保障。當用戶不在家等熟悉地點時,該功能要求用戶首次輸入生物特徵信息,並在一小時後再次輸入資訊才能存取和更改某些數據,如修改AppleID密碼或關閉失竊設備保護功能

小米汽車軟體提供遠端車控功能,讓使用者可以透過手機或電腦遠端控制車輛,例如開關車輛的門窗、啟動引擎、控制車輛的空調和音響等,下文就是這個軟體的使用及內容,一起了解下吧。小米汽車app功能及使用方法大全1、小米汽車app在3月25日上線蘋果AppStore,現在安卓手機的應用商店中也可以下載了;購車:了解小米汽車核心亮點和技術參數,可預約試駕、配置訂購您的小米汽車,支援線上處理提車待辦事項。 3.社群:了解小米汽車品牌資訊,交流用車體驗,分享精彩車生活;4、車控:手機就是遙控器,遠端控制,即時安防,輕

唧唧Down也可以叫做JJDown,這是專門為嗶哩嗶哩打造的一個視頻下載工具,但是很多小伙伴對這個軟體不了解,今天就讓小編為大家解答一下唧唧down是什麼?唧唧down怎麼使用吧。一、唧唧down的由來唧唧down起源於2014年,是個非常老牌的下載視訊軟體,介面採用Win10磁貼風格,簡潔美觀,操作方便。唧娜是唧唧down的看板娘,畫師是あさひクロイ。唧唧down一直致力於為使用者提供最佳的下載體驗,不斷更新和優化軟體,解決各種問題和bug,增加新的功能和特色。唧唧Down的功能唧唧Down是
