Smarty环境配置
从这里下载Smarty。
解压缩下载到的包,将解压缩后的目录名由Smarty.x.x.x修改为Smarty,并copy到想要安装的目录。如:
p:/Smarty。
修改php.ini文件的include_path设置,如:
include_path=".;P:\php-5.2.6\PEAR\pear;P:\Smarty\libs"
看个实际的例子:
打开Eclipse->File->New->PHP Project,命名为SmartyTest
假设我的Eclipse Workspace所在路径是:P:\EclipseWorkspace,那么PHP工程所在目录为:P:\EclipseWorkspace\SmartyTest
在其下创建目录Smarty,在其中再创建四个目录:
Smarty\templates
Smarty\templates_c
Smarty\cache
Smarty\configs
注:红色的必须创建并设置,以后再研究这几个目录的详细用途。
然后创建如下三个文件:
1. index.php在SmartyTest主目录下:
<?php
require('smarty_connect.php');
$smarty = new smarty_connect;
$smarty->assign('name','Ned');
$smarty->display('index.tpl');
?>
require('smarty_connect.php');
$smarty = new smarty_connect;
$smarty->assign('name','Ned');
$smarty->display('index.tpl');
?>
2. smarty_connect.php也在SmartyTest主目录下:
<?php
// load Smarty library
require('Smarty.class.php');
class smarty_connect extends Smarty
{
function smarty_connect()
{
// Class Constructor.
// These automatically get set with each new instance.
$this->Smarty();
$smarty_dir = "P:/EclipseWorkspace/SmartyTest/Smarty/";
$this->template_dir = $smarty_dir.'templates';
$this->config_dir = $smarty_dir.'configs';
$this->compile_dir = $smarty_dir.'templates_c';
$this->cache_dir = $smarty_dir.'cache';
$this->assign('app_name', 'Intranet');
}
}
?>
// load Smarty library
require('Smarty.class.php');
class smarty_connect extends Smarty
{
function smarty_connect()
{
// Class Constructor.
// These automatically get set with each new instance.
$this->Smarty();
$smarty_dir = "P:/EclipseWorkspace/SmartyTest/Smarty/";
$this->template_dir = $smarty_dir.'templates';
$this->config_dir = $smarty_dir.'configs';
$this->compile_dir = $smarty_dir.'templates_c';
$this->cache_dir = $smarty_dir.'cache';
$this->assign('app_name', 'Intranet');
}
}
?>
3. index.tpl文件在Smarty\templates下
<html>
<body>
Hello, {$name}!
</body>
</html>
<body>
Hello, {$name}!
</body>
</html>
这样就可以了。