ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Smarty环境配置

Smarty环境配置

原创 Linux操作系统 作者:iDotNetSpace 时间:2008-09-12 11:45:52 0 删除 编辑

从这里下载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/

-->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/

-->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/

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

 这样就可以了。

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

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5766165