smarty的应用,首先创建一个php文件
<?php
error_reporting(E_ALL & ~E_DEPRECATED);//避免过期出现的问题
include_once('mypdo.php');//读取你自己封装的连接数据库的文件
header('content-type:text/html;charset=utf-8');
$mypdo = new MyPdo();
$sql = "select * from book where id = ?";//SQL语句
$booklist = $mypdo->pdoPrepare($sql,array($_GET['id']));
$mypdo = null;//关闭数据库
include_once("libs/Smarty.class.php"); //包含smarty类文件
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
//$smarty->cache_dir = "./smarty_cache"; //缓存文件夹
//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突
//因此建议替换为<{}>
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$smarty->assign("booklist",$booklist);//传递的变量名和值;
$smarty->display('my.tpl')//需要显示的模板文件,后缀名可以随便写