A-A+

Smarty 完善的配置文件

2012年02月16日 PHP技术文章 暂无评论 阅读 48 views 次

include_once("smarty/Smarty.class.php"); //包含smarty类文件
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
/* 定义各个目录的路径 */
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->config_dir = "./configs"; //设置项目的配置
$smarty->cache_dir = "./cache"; //缓存文件夹
$smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存
/* 缓存生存时间变量 */
$smarty->cache_lifetime= 60;
//----------------------------------------------------
//左右边界符,默认为{},但实际应用当中容易与Javascript相冲突
//----------------------------------------------------
$smarty->left_delimiter = "{";
$smarty->right_delimiter = "}";
/* 使用 Smarty 赋值方法将一对名称/方法发送到模板中 */
$smarty->assign("title","第一个smarty实例");
$smarty->assign("content","这是内容");

/* 使用 Smarty 赋值方法将一对数组/方法发送到模板中 */
$arr = array('title'=>'数组标题','content'=>'数组内容');
$smarty->assign('arr',$arr); //索引显示:{$arr[0]} 键值显示:{$arr.title}
/* 显示模板 */
$smarty->display("index.html");

标签:

给我留言