安装与使用smarty

1.安装

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

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

  

   将解压后的文件存放在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个目录。

  

  其中,

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

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

  index.php代码:

  

   打开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/

 

posted on 2013-07-12 12:59  cccccccccccc  阅读(575)  评论(0编辑  收藏  举报

导航