smarty配置学习系列之一

最近要用到smarty来做一个管理销售后台,基于shopnc的数据表。添加代理商功能和邀请返利的功能。so……这个系列具体有多少我也不清楚,smarty我也是第一次接触,原来听朋友们讲过这个很利于开发。本来是想用TP来做的 ,但是感觉自己水平不够,哎……一起学习smarty吧!!!

 

第一步:.配置smarty。

 

去官网下载smarty。我选择的是zip,版本Smarty 3.1.12。

环境:wampserver

在www目录下建立houtai文件夹,将压缩包的libs复制到www文件夹里,更名为class,并且新建templates、templates_c、configs、includes四个文件夹。

 

templates文件夹放置模版文件。

templates_c文件夹放置编译过的php文件,可以有效的提高smarty的第二次运行效率。

configs放置配置文件。

includes放置一些function函数。

好了,下面在战点根目录建立一个main.php的配置文件,代码如下

<?php
define('__ROOTSITE','F:/WMAP/www/houtai/');
include_once('class/Smarty.class.php');

$tpl = new Smarty();
$tpl->template_dir=__ROOTSITE.'/templates/';
$tpl ->compile_dir=__ROOTSITE.'/templates_c/';
$tpl->config_dir=__ROOTSITE.'/configs/';
$tpl->left_delimiter='<{';
$tpl->right_delimiter='}>';


现在smarty已经配置完成了,应该测试一下配置是否成功!

根目录下新建index.php,

<?php

require('main.php');

$tpl->assign("site","我要学习网");
$tpl->assign("url","http://www.wypifa.com");
$tpl->display('index.htm');

 

在templates文件夹下再建立一个index.htm,与display('index,htm')的index.htm对应

代码如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试</title>
</head>

<body>
<a href="<{$url}>"><{$site}></a>
</body>
</html>


好,打开浏览器http://localhost/houtai/,如下图所示

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值