Smarty入门教程一----Smarty的安装
2015-01-28 00:00
423 查看
1. 下载Smarty最新版: http://www.smarty.net/download
2. libs目录下的文件都是Smarty需要的库文件,只要将该文件夹拷贝到要使用Smarty技术的网站根目录就能够使用Smarty了。为了不和已有的文件夹重名,可以修改文件夹的名字为Smarty。
3.在网站根目录下建立如下的目录结构 来测试Smarty的使用。
----Smarty-learn
--------------------smarty(smarty的库文件)
--------------------templates---cache
------------------------------------config
------------------------------------templates--------index.html(模版文件)
------------------------------------templates_c
--------------------index.php
index.html 的内容:
<html>
<title><head>test smarty</head></title>
<body>
{$color}
</body>
</html>
index.php的内容:
<?PHP
//引用类文件?
require 'smarty/Smarty.class.php';
$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;
$hello = "hello smarty!";
$smarty->assign('hello',$hello);
$bgcolor = "green";
$smarty->assign('color',$bgcolor);
$smarty->display('index.html');
?>
在浏览器输入localhost:/Smarty-learn,如果出现green,说明测试成功,Smarty没有任何问题,已经可以使用了。
这样的目录结构并不是必须的,只要在使用Smarty的时候配置好这几个目录的路径,任何目录结构都是可以的。但是建议这样使用,层次清楚,不影响网站其他部分。
2. libs目录下的文件都是Smarty需要的库文件,只要将该文件夹拷贝到要使用Smarty技术的网站根目录就能够使用Smarty了。为了不和已有的文件夹重名,可以修改文件夹的名字为Smarty。
3.在网站根目录下建立如下的目录结构 来测试Smarty的使用。
----Smarty-learn
--------------------smarty(smarty的库文件)
--------------------templates---cache
------------------------------------config
------------------------------------templates--------index.html(模版文件)
------------------------------------templates_c
--------------------index.php
index.html 的内容:
<html>
<title><head>test smarty</head></title>
<body>
{$color}
</body>
</html>
index.php的内容:
<?PHP
//引用类文件?
require 'smarty/Smarty.class.php';
$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;
$hello = "hello smarty!";
$smarty->assign('hello',$hello);
$bgcolor = "green";
$smarty->assign('color',$bgcolor);
$smarty->display('index.html');
?>
在浏览器输入localhost:/Smarty-learn,如果出现green,说明测试成功,Smarty没有任何问题,已经可以使用了。
这样的目录结构并不是必须的,只要在使用Smarty的时候配置好这几个目录的路径,任何目录结构都是可以的。但是建议这样使用,层次清楚,不影响网站其他部分。
相关文章推荐
- Smarty安装和入门教程
- PHP模板之Smarty安装与使用入门教程
- Smarty入门教程一----Smarty的安装
- PHP模板之Smarty安装与使用入门教程
- PHP模板之Smarty安装与使用入门教程
- PHP模板之Smarty安装与使用入门教程
- PHP模板之Smarty安装与使用入门教程
- Smarty安装和入门教程 .
- PHP模板之Smarty安装与使用入门教程
- 安装Microsoft .NET Framework SDK 快速入门教程出现错误
- Windows环境下smarty安装简明教程
- RH9安装SVN+win用户使用---新手入门教程 推荐
- smarty下载及入门教程(转)
- Windows环境下smarty安装简明教程
- DNN快速入门教程4 - 如何安装和汉化DotNetNuke5(视频)
- Subversion快速入门教程,软件下载,服务器和客服端安装,导入项目,基本客服端操作
- Smarty安装教程
- Smarty中文手册,Smarty教程,Smarty模板的入门教材
- Photoshop入门教程:字体安装及使用
- linux入门教程(2)---安装指南