php Smarty点点滴滴1

1 首先下载Smarty,从官方网站下载就行了,

2 解压缩找到libs这是我们需要的类库。

3 拷贝libs到网站的根目录重命名(也可以不重命名随便自己爱好)这里我重命名为Smarty

4 然后在Smarty(我的libs重命名的)下创建目录“templates”,“templates_c”,"configs","cache "

5 看文件名字就知道是干什么用的了呵呵,在templates 存放的是模版,这里新建一个index.tpl

   index.tpl内容如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{$title}</title>
</head>
{$content}
<body>
</body>
</html>

 在Smarty同级别创建文件index.php

代码如下index.php

<?PHP
/*定义服务器的绝对路径*/
define('BASE_PATH','C:\AppServ\www\\');
/*定义smarty目录相对路径*/
define('SMARTY_PATH','\tests\Smarty\\');
/*定义Smarty类库文件*/
require BASE_PATH.SMARTY_PATH.'Smarty.class.php';

/*实例化一个Smarty*/
$smarty = new Smarty;//创建一个类
$smarty->template_dir = BASE_PATH.SMARTY_PATH.'templates/';
$smarty->compile_dir = BASE_PATH.SMARTY_PATH.'templates_c/';
$smarty->config_dir = BASE_PATH.SMARTY_PATH.'configs/';
$smarty->cache_dir = BASE_PATH.SMARTY_PATH.'cache/';


/*使用Smarty 赋值方法将一对儿名称/方法发送到模版中*/
$smarty->assign('title','第一个Smarty程序');
$smarty->assign('content','欢迎到来学习\'Smarty模版\'!');


$smarty->display('index.tpl');




?>

 

ok最简单的Smarty创建成功了,上面的注释很明确了,这里就不解释了呵呵

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章