CodeIgniter生成靜態(tài)頁的方法
本文實例講述了CodeIgniter生成靜態(tài)頁的方法。分享給大家供大家參考,具體如下:
現在我們來開發(fā)如何讓CI框架生成靜態(tài)頁面.下面直接帖代碼:
$this->output->get_output();
使用這個方法,你可以可以得到將要輸出的數據,并把它保存起來,留著它用(我們做新聞類型網站的時候,常常需要生成靜態(tài)的HTML文件).
$string = $this->output->get_output();
$this->load->helper('file');
write_file('./lianglong_codeigniter.html', $string);
比如我們要輸出的頁面是要加載某個視圖后的數據,那么我們就在
$this->load->view('welcome_lianglong);
之后加入
$this->output->get_output();
并把值給一個變量如$lianglong存儲起來.再用CI的FILE中的write_file輔助函數,生成你要的文件,如下例
function sc(){
$this->load->helper('file');
$this->load->view('welcome_message');
$lianglong=$this->output->get_output();
if ( !write_file('./lianglongfile.html', $lianglong))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
}
或者:
function sc(){
$this->load->helper('file');
$liangdong=$this->load->view('welcome_message',$data,true);
if ( !write_file('./lianglongfile.html', $lianglong))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
}
更多關于CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php優(yōu)秀開發(fā)框架總結》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《Zend FrameWork框架入門教程》、《php面向對象程序設計入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
希望本文所述對大家基于CodeIgniter框架的PHP程序設計有所幫助。
相關文章
網頁游戲開發(fā)入門教程二(游戲模式+系統(tǒng))
網頁游戲開發(fā)入門教程二(游戲模式+系統(tǒng))2009-11-11
windows7配置Nginx+php+mysql的詳細教程
這篇文章主要介紹了windows7配置Nginx+php+mysql的詳細教程 的相關資料,需要的朋友可以參考下2016-09-09
php中使用session_set_save_handler()函數把session保存到MySQL數據庫實例
這篇文章主要介紹了php中使用session_set_save_handler()函數把session保存到MySQL數據庫實例,本文同時還給出了Session保存到Mysql數據庫存儲類,需要的朋友可以參考下2014-11-11

