当前位置:编程学习 > php >>

Codeigniter 生成静态页面

    使用CI来生成静态页面,其实很简单,就像论坛里面说的那样,读出页面中的数据,再写入html文件中,最后显示这个html文件就行了,好吧,上码。
 
 
[php] 
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
                
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);  
        }  
                            
   ......  
    }    
}  
 
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
              
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);
        }
                      &n
补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,