采用smarty编写的程序可以获得最大速度的提高,这一点是相对于其它的模板引擎技术而言的。
*/
代码如下 | 复制代码 |
$servername = 'localhost'; $dbname='whois';//数据库教程名称,需修改为您当前使用的库名称 $tbname='post';//数据表名称,不用修改 $name='root';//数据库用户名,需修改 $password='xxxxxxx';//数据库链接密码,需修改 require_once 'smarty/libs/Smarty.class.php教程'; $smarty = new Smarty(); //初始化类 $smarty->template_dir = "smarty/templates/templates"; //设置模板目录 $smarty->compile_dir = "smarty/templates/templates_c"; //设置编译目录 $smarty->config_dir = "smarty/templates/config"; //配置文件目录 $smarty->cache_dir = "smarty/templates/cache"; // $smarty->caching = false; $db=mysql教程_connect($servername,$name,$password)or die ('服务器连接错误。'); $ii=mysql_select_db("$dbname")or die("不能选择数据库"); mysql_query("set names 'gbk'"); $title ='smarty 教程'; $smarty->display('index.html'); //使用 smarty emplates emplatesindex.html 模板 |
?>
index.html模板文件
代码如下 | 复制代码 |
<title><!--{$title}--></title> <meta name="keywords" content="<!--{$keyword}-->" /> <meta name="description" content="<!--{$description}-->" /> {include file='head.tpl'} |
<?
/*
smarty 模板变量
.{$name}: 模板变量,smarty中的核心组成,采用smarty定义的左边界符{与右边界符}包含着、以PHP变量形式给出,在smarty程序中将使用
$smarty->assign("name", "李晓军");将模板中的$name替换成“李晓军”三个字。
*/
时间: 2024-05-20 23:42:51