这里下载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主目录下:

Smarty环境配置<?php
Smarty环境配置
require('smarty_connect.php');
Smarty环境配置
Smarty环境配置
$smarty = new smarty_connect;
Smarty环境配置
Smarty环境配置
$smarty->assign('name','Ned');
Smarty环境配置
Smarty环境配置
$smarty->display('index.tpl');
Smarty环境配置
?>

 

 2. smarty_connect.php也在SmartyTest主目录下:

 

Smarty环境配置<?php
Smarty环境配置
// load Smarty library
Smarty环境配置
require('Smarty.class.php');
Smarty环境配置
Smarty环境配置
class smarty_connect extends Smarty 
Smarty环境配置{
Smarty环境配置   
function smarty_connect()
Smarty环境配置   {
Smarty环境配置        
// Class Constructor. 
Smarty环境配置        // These automatically get set with each new instance.

Smarty环境配置
        $this->Smarty();
Smarty环境配置        
$smarty_dir = "P:/EclipseWorkspace/SmartyTest/Smarty/";
Smarty环境配置        
$this->template_dir = $smarty_dir.'templates';
Smarty环境配置        
$this->config_dir = $smarty_dir.'configs';
Smarty环境配置        
$this->compile_dir = $smarty_dir.'templates_c';
Smarty环境配置        
$this->cache_dir = $smarty_dir.'cache';
Smarty环境配置        
$this->assign('app_name', 'Intranet');
Smarty环境配置   }
Smarty环境配置}
Smarty环境配置
Smarty环境配置
?>

3. index.tpl文件在Smarty\templates下

Smarty环境配置<html>
Smarty环境配置
<body>
Smarty环境配置 Hello, {$name}!
Smarty环境配置
</body>
Smarty环境配置
</html>
Smarty环境配置

 这样就可以了。

相关文章: