手机
当前位置:查字典教程网 >编程开发 >php教程 >CodeIgniter生成静态页的方法
CodeIgniter生成静态页的方法
摘要:本文实例讲述了CodeIgniter生成静态页的方法。分享给大家供大家参考,具体如下:现在我们来开发如何让CI框架生成静态页面.下面直接帖代...

本文实例讲述了CodeIgniter生成静态页的方法。分享给大家供大家参考,具体如下:

现在我们来开发如何让CI框架生成静态页面.下面直接帖代码:

$this->output->get_output();

使用这个方法,你可以可以得到将要输出的数据,并把它保存起来,留着它用(我们做新闻类型网站的时候,常常需要生成静态的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框架的PHP程序设计有所帮助。

【CodeIgniter生成静态页的方法】相关文章:

PHP file_get_contents函数读取远程数据超时的解决方法

php统计数组元素个数的方法

Get或Post提交值的非法数据处理

php猴子选大王问题解决方法

PHP生成plist数据的方法

PHP生成静态页面详解

复杂检索数据并分页显示的处理方法

php实现图片转换成ASCII码的方法

php递归调用删除数组空值元素的方法

CodeIgniter针对lighttpd服务器URL重写的方法

精品推荐
分类导航