一聚教程网:一个值得你收藏的教程网站

热门教程

(PHP)配置,使用Smarty技术

时间:2022-07-02 10:48:43 编辑:袖梨 来源:一聚教程网

相关知识:

  1、2、模板引擎Smarty深入浅出介绍Smarty技术是PHP的精髓所在, 随着PHP版本的逐渐提高,原来的很多方法也许太过时了,下面我就针对最新的PHP5.1.1版本的使用,配置说说如何配置。下面是一步步的来的,请注重:1、在官方下载模板库文件:下载了就解压,看见一个文件夹了,是个smarty.x.x,打开,里面有个libs文件夹,ok,注重这个东西就是我们要的。2、在你的网站目录下面,比方我的php网站IIS在物理硬盘的d:/web/web/php下面,在这个文件夹下面建立:一个文件夹test,然后我们把刚提到的 libs文件夹复制道test文件夹下面。 * 请看本文最后的注释 Tips13、在test文件夹下面再建立4个文件夹:

  cache

  configs

  templates

  templates

  _c4、建立文件text.htm:<$content>保存在templates目录下面。5、然后建立文件模板配置文件: config.php

  include../libs/Smarty.class.php;$NowPathArray=explode(test,str_replace(,/,dirname(__FILE__)));

  @define(root_path, $NowPathArray[0]);

  @define(__SITE_ROOT, root_path.test);

  $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->center_delimiter = <;

  $tpl->center_delimiter =>;?>保存在主目录也就是test下面。6、在test新建文件test.php文件,输入:

  require config.php;

  $tpl->assign(title, 测试成功了,这是标题);

  $tpl->assign(content, 这是内容);

  $tpl->display(test.htm);?>7、在浏览器测试test.php显示为:这是内容恭喜,配置成功.否则,失败,再检查是不是按照我说的来的。

  Tips1

  :为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的;Windows:path1;path2include_path = .;c:phpincludes改为:;Windows:path1;path2include_path=.;c:php includes;d:webwebphplibs使用模板的时候,像前面一样的方式使用,不要:include.. /libs/Smarty.class.php;直接使用就行了的。

热门栏目