最近要用到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/,如下图所示