首页 技术 正文
技术 2022年11月13日
0 收藏 752 点赞 4,603 浏览 1268 个字

1.安装

下载最新的smarty。下载地址:http://www.smarty.net/download

下载成功后,解压压缩包后的文件如图所示:

安装与使用smarty

将解压后的文件存放在web文档根目录外的某个位置。windows下,这个位置可能是:

C:\php\includes\Smarty-3.1.13

2. 因为需要将smarty类库包含在应用程序中,所以要确保此位置(C:\php\includes\Smarty-3.1.13)包含在php的include_path中。将该路径附加在include_path后面:

; Windows: “\path1;\path2”
  include_path = “.;C:\xampp\php\PEAR;C:\php\includes\Smarty-3.1.13\libs;”

配置好后,重启web svr。

3. 在网站目录下创建存储smarty模版和配置文件的4个目录。

安装与使用smarty

其中,

templates:放置所有网站模版。index.php要display的welcome.tpl就存放在此目录下。

htdoc:自定义文件夹。我这里存放的是网站入口:index.php。

index.php代码:

安装与使用smarty

打开index.php,页面输出welcome.tpl中定制的内容,说明smarty安装成功。

PS:

index.php中设置smarty的TemplateDir、CompileDir、ConfigDir、CacheDir时,如果路径不对,会报一下错误:

Fatal error: Uncaught exception ‘SmartyException’ with message ‘Unable to load template file ‘welcome.tpl” in C:\php\includes\Smarty-3.1.13\libs\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0 C:\php\includes\Smarty-3.1.13\libs\sysplugins\smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch(‘welcome.tpl’, NULL, NULL, NULL, true) #1 E:\www\phptest\smarty demo\htdocs\index.php(14): Smarty_Internal_TemplateBase->display(‘welcome.tpl’) #2 {main} thrown in C:\php\includes\Smarty-3.1.13\libs\sysplugins\smarty_internal_templatebase.php on line 127

   此时一定要检查代码中设置的路径是否正确。

   参考:http://ralphdc.blog.163.com/blog/static/17031938520111117114239220/

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,486
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,126
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,287