学习smarty手记一,如何配置smarty

学习PHPSMARTY

下载

先在smarty.php.net下载最新smarty

 

一般做法:

1解压smarty.

2 libs文件夹放在你的WEB目录下,我是放在smarty下的,目录情况如下:e:/wwwroot/smarty/libs
smarty目录下新建如下文件夹:
templates
(这里放你的模板文件,即tpl文件)
configs
templates_c
(自动将编译完的文件转成PHP放在这)
cache
然后在wwwroot目录下建立index.php

<?php
     
     
include "smarty/libs/Smarty.class.php";
     
     
define('__SITE_ROOT', 'e:/wwwroot/smarty'); // 最後沒有斜線
      
      
$tpl = new Smarty();
     
     
$tpl->template_dir = __SITE_ROOT . "/templates/";
     
     
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
     
     
$tpl->config_dir = __SITE_ROOT . "/configs/";
     
     
$tpl->cache_dir = __SITE_ROOT . "/cache/";
     
     
//$tpl->left_delimiter = '<{';  可根据需要更改。
      
      
//$tpl->right_delimiter = '}>';
     
     
$tpl->assign('name','world!');
     
     
$tpl->display('index.tpl')
     
     

   
   
    
     
   
   
?>
     
     

template目录下建立index.tpl

<!DOCTYPE HTML PUBLIC "-//W 3C //DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title> New Document </title>

<meta name="Generator" content="EditPlus">

<meta name="Author" content="">

<meta name="Keywords" content="">

<meta name="Description" content="">

</head>

 

<body>

hello,{$name}~.

</body>

</html>

 

问题一 代码里必须重新定义了绝对路径

 解决方法 (注明参考朋友发过来的code)得出一种解决方式

1、将libs文件夹放在你的WEB目录下,我是放在smarty下的,目录情况如下:e:/wwwroot/smarty/libs

改为。去掉libs目录,直接把里面所有文件直接放到 e/:wwwroot/lib ,这样解压所有的smarty文件直接放到/www/lib/smarty下。

2、在根目录下建立include目录,然后新建一个smarty.php文件

配置为

<?

include("lib/smarty/Smarty.class.php");

$tpl = new Smarty();

$tpl->template_dir = " templates /";

$tpl->compile_dir =  " templates_c /";

$tpl->config_dir =  "configs/";

$tpl->cache_dir = "cache/";

?>

 

3index.php文件为

 

 

<?php
     
     
include "include/Smarty.php";
     
     
$tpl->assign('name','world!');
     
     
$tpl->display('index.tpl')
     
     

   
   
    
     
   
   
?>
     
     
4.这样一来大家都看清楚了吧,这样就不需要写上绝对路径啦define('__SITE_ROOT', 'e:/wwwroot/smarty'); // 最後沒有斜線
      
      

 

 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值