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

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt php
require ( ' smarty_connect.php ' );

$smarty   =   new  smarty_connect;

$smarty -> assign( ' name ' , ' Ned ' );

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

 

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

 

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt 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 ' );
   }
}

?>

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

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt < html >
< body >
 Hello, {$name}!
body >
html >

 这样就可以了。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-446851/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12639172/viewspace-446851/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值