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創建成功了,上面的註釋很明確了,這裏就不解釋了呵呵

 

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