您的位置:首页 > 其它

Smarty入门教程二-----使用配置文件避免每次都配置路径

2014-10-17 21:04 477 查看
1. 写一个配置文件smarty.ini.php:

<?PHP

//引用类文件?

require 'smarty/Smarty.class.php';

$smarty = new Smarty;

//$smarty=new Smarty;

//设置各个目录的路径,这里是安装的重点

$smarty->template_dir="templates/templates";

$smarty->compile_dir="templates/templates_c";

$smarty->config_dir="templates/config";

$smarty->cache_dir="templates/cache";

//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决

$smarty->caching=false;

?>

2. 在使用模板的index.php文件中:

<?php

    include "smarty.ini.php";

    $title="Smarty-Learn-Test";

    $content="Smarty_content哈哈";

    $auth="MarcoFly";

    $website="www.MarcoFly.com";

    $smarty->assign("title",$title);

    $smarty->assign("content",$content);    

    $smarty->assign("auth",$auth);

    $smarty->assign("website",$website);

    $smarty->display("index.html");

?>

相应的index.html文件:

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>{$title}</title>

</head>

<body>

<p>内容:{$content}</p>

<p>作者:{$auth}</p>

<p>网址:{$website}</p>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  smarty