发新话题
打印

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

学习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 "-//W3C//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/";

?>

3、index.php文件为

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

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

相关资源:
[smarty实例教学]用smarty打造你的留言板(一)
[smarty实例教学]用smarty打造你的留言板(二)
[smarty实例教学]用smarty打造你的留言板(三)
[smarty实例教学]用smarty打造你的留言板(四)
努力为phpres做贡献
时刻准备着,当机会来临时你就成功了
打好基础,增加社会经验
资深技术工程师是我的梦想
承接各种团体网站外包服务和各种it技术培训
准备申请AJAX版大,希望大家支持~~

TOP

路过,鼓励啊

TOP

顶顶! :lol :lol :lol

TOP

发新话题