smarty 安装与配置

1.在www.smarty.net 下载smarty,解压 。假设解压目录为Smarty-2.6.19。
2.在网站主目录下建立文件夹smartytest(比如:XAMPP下 E:/xampp/htdocs/smartytest) 同时在 smartytest目录下建立如下几个目录:cache ,configs ,templates, templates_c。并且将Smarty-2.6.19下libs目录全部复制到smartytest目录下。
3.将以下代码保存到config.php中 并将文件保存到 smartytest下(smartytest/config.php)
<?php 
    include "libs/Smarty.class.php"; 
   @define('__SITE_ROOT', str_replace("//","/",dirname(__FILE__)));
    $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 = '}>'; 
?> 
4. 修改php.ini中(我的是XAMPP 修改的是php/php5.ini和apache/bin/php.ini)
     ; Windows: "/path1;/path2"
    include_path = ".;E:/xampp/php/pear/;E:/xampp/htdocs/smartytest/libs" (指向smartytest 中的libs 绝对路径).
     改后 重启apache.

5.测试:将以下代码保存到 test.php 中 smartytest/test.php
    <?php 
    require "config.php"; 
    $tpl->assign("title", "测试成功了,这是标题"); 
    $tpl->assign("content", "这是内容"); 
    $tpl->display('test.html'); 
?>

   将以下代码保存 test.html中 smartytest/templates/test.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head> 
<body>
<{$content}>
</body>
</html>

6.运行test.php 文件(XAMPP下 http://localhost/smartytest/test.php


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值