PHP之Smarty学习

参考网络上的资料,使用Smarty可以简单的测试:

1.解压Smarty到网站目录下,比如起名libs.

2.建立templates,templates_c,configs,cache目录

3.建立测试页面:index.php

<?php
require "main.php";

//$tpl在main.php中定义


$tpl->assign("title", "测试用的网页标题");
$tpl->assign("content", "测试用的网页内容");
// 上面两行也可以用这行代替
// $tpl->assign(array("title" => "测试用的网页标题", "content" => "测试用的网页内容"));
$tpl->display('Index.htm');
?>

4.在templates下建立模板文件index.htm

<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title><{$title}></title>
  </head>
  <body>
  <{$content}>
  </body>
  </html>

5.建立main.php

<?php

/*下面这加如果不加会报告错误:

Notice: Undefined variable: _SESSION in E:\PHPnow-1.5.1\vhosts\xxh.com\libs\Smarty.class.php on line 585

不知道为什么

*/
session_start();//开启session
include "libs/Smarty.class.php";
define('__SITE_ROOT', 'E:/PHPnow-1.5.1/vhosts/xxh.com'); // 最后没有斜线
$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 = '}>';
?>

6.打开index.php即可以测试Smarty了.

转载于:https://www.cnblogs.com/GarfieldTom/archive/2009/05/20/1467260.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值