我也写了1个简单的类 请指教下
<?php
/**
* @Description: 用smarty生成html页面的类
* @CreateDate : 2008-12-22 by xingxing
* @Author : xingxing
* @Version : v1.0
* @ModifyDate :
*/class CreateHtml{
private $mHtmlName = ''; #生成html文件名
private $mDirName = ''; #存放html文件的目录
private $mTemplateName = ''; #smarty模板名
private $mMode = 'wb'; #打开写入文件模式
private $mSmarty ; #引用smarty
private $handle = false; #打开文件指针
public function __construct($dirName, $htmlName, $templateName, $smarty) {
$this->mDirName = $this->getDirName($dirName);
$this->mHtmlName = $htmlName;
$this->mTemplateName = $templateName;
$this->mSmarty = $smarty;
} private function getDirName($dirName) {
if(empty($dirName)) {
$path = getcwd();
$dirName = $path.'/'.date('Ym');
}
return $dirName;
}
private function getHtmlName() {
$file_name = (substr($this->mDirName, -1, 1) == '/') ? $this->mDirName.$this->mHtmlName : $this->mDirName.'/'.$this->mHtmlName;
return $file_name;
}
private function dirIsExists() {
if(!file_exists($this->mDirName)) {
//$m_dir = @mkdir(dirname($this->mDirName), 0777);
if(!@mkdir($this->mDirName, 0777)) {
die($this->mDirName.'donot create;');
}
}
}
private function unlikFile() {
if(is_file($this->getHtmlName())) unlink($this->getHtmlName());
}
private function openFileHandle() {
if($this->handle = @fopen($this->getHtmlName(), $this->mMode)) {
return $this->handle;
} else {
return false;
}
}
private function closeFileHandle() {
return @fclose($this->handle);
} private function writeContent($content) {
if(@fwrite($this->handle, $content)) {
return true;
} else {
return false;
}
}
/**
* @Description: 创建html文件函数
* */
public function createHtmlFile(){
$this->dirIsExists();
if($this->openFileHandle()) {
$content = $this->mSmarty->fetch($this->mTemplateName);
if(!$this->writeContent($content)) {
die('文件不能写');
}
}
$this->closeFileHandle();
chmod($this->getHtmlName(), 0777);
}
}#Example
/*
include('../libs/Smarty.class.php'); #smarty类文件
$smarty = new Smarty();$smarty->template_dir = 'html_dir';
$smarty->compile_dir = 'html_c';
$smarty->cache_dir = 'html_cache';
$smarty->cache_lifetime = 0;
$smarty->caching = FALSE;
$smarty->left_delimiter = '<{';
$smarty->right_delimiter= '}>';$c='他人笑我太傻太疯癫,我笑他人看不穿';
$smarty->assign('title', '静态文件_2');
$smarty->assign('titleName', '我来了啊');
$smarty->assign('name', '人生如戏,戏如人生');
$smarty->assign('content', $c);
#html 生成的文件目录, 8。html生成的文件名 ,createhtml_1.html 模板名
$create_html = new CreateHtml('html', '8.html', 'createhtml_1.html', $smarty);
#调用生成静态文件名方法
$create_html->createHtmlFile();
*/
?>有什么建议请提出来
<?php
/**
* @Description: 用smarty生成html页面的类
* @CreateDate : 2008-12-22 by xingxing
* @Author : xingxing
* @Version : v1.0
* @ModifyDate :
*/class CreateHtml{
private $mHtmlName = ''; #生成html文件名
private $mDirName = ''; #存放html文件的目录
private $mTemplateName = ''; #smarty模板名
private $mMode = 'wb'; #打开写入文件模式
private $mSmarty ; #引用smarty
private $handle = false; #打开文件指针
public function __construct($dirName, $htmlName, $templateName, $smarty) {
$this->mDirName = $this->getDirName($dirName);
$this->mHtmlName = $htmlName;
$this->mTemplateName = $templateName;
$this->mSmarty = $smarty;
} private function getDirName($dirName) {
if(empty($dirName)) {
$path = getcwd();
$dirName = $path.'/'.date('Ym');
}
return $dirName;
}
private function getHtmlName() {
$file_name = (substr($this->mDirName, -1, 1) == '/') ? $this->mDirName.$this->mHtmlName : $this->mDirName.'/'.$this->mHtmlName;
return $file_name;
}
private function dirIsExists() {
if(!file_exists($this->mDirName)) {
//$m_dir = @mkdir(dirname($this->mDirName), 0777);
if(!@mkdir($this->mDirName, 0777)) {
die($this->mDirName.'donot create;');
}
}
}
private function unlikFile() {
if(is_file($this->getHtmlName())) unlink($this->getHtmlName());
}
private function openFileHandle() {
if($this->handle = @fopen($this->getHtmlName(), $this->mMode)) {
return $this->handle;
} else {
return false;
}
}
private function closeFileHandle() {
return @fclose($this->handle);
} private function writeContent($content) {
if(@fwrite($this->handle, $content)) {
return true;
} else {
return false;
}
}
/**
* @Description: 创建html文件函数
* */
public function createHtmlFile(){
$this->dirIsExists();
if($this->openFileHandle()) {
$content = $this->mSmarty->fetch($this->mTemplateName);
if(!$this->writeContent($content)) {
die('文件不能写');
}
}
$this->closeFileHandle();
chmod($this->getHtmlName(), 0777);
}
}#Example
/*
include('../libs/Smarty.class.php'); #smarty类文件
$smarty = new Smarty();$smarty->template_dir = 'html_dir';
$smarty->compile_dir = 'html_c';
$smarty->cache_dir = 'html_cache';
$smarty->cache_lifetime = 0;
$smarty->caching = FALSE;
$smarty->left_delimiter = '<{';
$smarty->right_delimiter= '}>';$c='他人笑我太傻太疯癫,我笑他人看不穿';
$smarty->assign('title', '静态文件_2');
$smarty->assign('titleName', '我来了啊');
$smarty->assign('name', '人生如戏,戏如人生');
$smarty->assign('content', $c);
#html 生成的文件目录, 8。html生成的文件名 ,createhtml_1.html 模板名
$create_html = new CreateHtml('html', '8.html', 'createhtml_1.html', $smarty);
#调用生成静态文件名方法
$create_html->createHtmlFile();
*/
?>有什么建议请提出来
首先是静态页
还有分页静态
如果有不同的页,要不同的模板和变量
静态化的缓存机制
静态页的生机机制和删除机制
url重写
其实也谈不上静态化只是做一个课程导出的功能课程就是几个简单的动态页面可以换不一样的板子课程的链接地址在数据库中我可以取出来有些分页的地址需要计算一下根据固定的链接地址用file_get_contents直接取内容就可以 了取出页面然后替换里面的html路径 替换图片 还有flash路径链接的话我是替换成
index--action-book-page-1.htm
这种模式主要就是正则表达式
麻烦的就是一个ajax的树型菜单
还要替换掉js文件里面的部分内容快做完了才想起来其实这东西真正做完也就两个星期吧之前一直都是在走弯路,
做到一半,又开始优化前面的部分代码再加分100