PHP+jQuery 注册模块的改进(三):更新到Smarty3.1
php  /  管理员 发布于 7年前   150
Smarty3.1X( 最新版本 3.1.19) 比起Smarty2.x修改了不少特性。我把这个模块使用Smarty3.1.18 ( 下载地址http://www.smarty.net/files/Smarty-3.1.18.zip )重新修改了一遍,是项目文件和目录看起来更干净更有调理。 把Smarty压缩包中的libs文件夹拷贝至模块根目录下,然后根目录创建init.inc.php: /* *********************Smarty设置*********************** */ require ROOT.'libs/Smarty.class.php'; //Smarty3设置默认路径 $smarty->caching = false; /***********************************************************/ //根目录url方式 //模版目录url方式 创建初始化文件中出现的templates,templates_c,plugins,cache,configs文件夹。 修改的文件都比较相似,而且也非常easy,这里列出register.html和register.php文件的修改。 register.html是注册的前台页面,路径是/templates/register.html
/**
file:init.inc.php Smarty对象的实例化及初始化文件
*/
//根目录路径方式,用于Smarty设置
define("ROOT",str_replace("\\","/",dirname(__FILE__))."/");
$smarty = new Smarty();
$smarty ->setTemplateDir(ROOT.'templates/')
->setCompileDir(ROOT.'templates_c/')
->setPluginsDir(ROOT.'plugins/')
->setCacheDir(ROOT.'cache/')
->setConfigDir(ROOT.'configs');
$smarty->cache_lifetime = 60*60*24; //模版缓存有效时间为1天
$smarty->left_delimiter = '<{';
$smarty->right_delimiter = '}>';
$PHP_SELF=$_SERVER['PHP_SELF'];
$ROOT_URL='http://'.$_SERVER['HTTP_HOST'].substr($PHP_SELF,0,strrpos($PHP_SELF,'/')+1);
define(ROOT_URL,$ROOT_URL);
define("Template_Dir",$ROOT_URL.'templates');
<{*导入header.html*}>
<{include file="header.html"}>