PHP教程:配置smarty开发环境_PHP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

PHP教程:配置smarty开发环境

作者:黑客防线网安PHP教程基地 来源:黑客防线网安PHP教程基地 浏览次数:0

本篇关键词:开发环境配置教程
黑客防线网安网讯:  首先到http://www.smarty.net上下载最新的smarty模板引擎,解压Smarty-2.6.26.zip,改名Smarty-2.6.26目录为smarty。    拷贝smarty目录到你希望的目录D:xamppxamppsmarty。    ...
  首先到http://www.smarty.net上下载最新的smarty模板引擎解压Smarty-2.6.26.zip改名Smarty-2.6.26目录为smarty
  
  拷贝smarty目录到你希望的目录D:xamppxamppsmarty
  
  在php.ini的include_path加入smarty库目录,如下:
  
  include_path=“.;D:xamppxamppphpPEAR;D:xamppxamppsmartylibs”
  
  在你的php项目目录新建两个子目录放配置文件和模板:config和templates
  
  D:xamppxampphtdocsconfig
  
  D:xamppxampphtdocs emplates
  
  smarty项目目录新建两个目录cache和templates_c存放缓存和编译过的模板:
  
  D:xamppxamppsmartycache
  
  D:xamppxamppsmarty emplates_c
  
  在需要调用smarty库的php文件中写入代码:
  
  1
  
  2
  
  3
  
  4
  
  5
  
  6
  
  7
  
  8
  
  9
  
  10
  
  11
  
  //thisisD:xamppxampphtdocsindex.php
  
  //loadsmartylibrary
  
  require('Smarty.class.php');
  
  $smarty=newSmarty();
  
  $smarty->template_dir='d:/xampp/xampp/htdocs/templates';//指定模板存放目录
  
  $smarty->config_dir='d:/xampp/xampp/htdocs/config';//指定配置文件目录
  
  $smarty->cache_dir='d:/xampp/xampp/smarty/cache';//指定缓存目录
  
  $smarty->compile_dir='d:/xampp/xampp/smarty/templates_c';//指定编译后的模板目录
  
  $smarty->assign('name','fishboy!');
  
  $smarty->display('index.tpl');
  
  再新建一个D:xamppxampphtdocs emplatesindex.tpl文件
  
  1
  
  2
  
  3
  
  4
  
  5
  
  6
  
  7
  
  8
  
  9
  
  10
  
  <html>
  
  <head><title>hello,{$name}!</title>
  
  <scriptlanguage="javascript"type="text/javascript">
  
  alert('{$name}');
  
  </script>
  
  </head>
  
  <body>
  
  hello,{$name}!
  
  </body>
  
  </html>
  
  打开http://localhost/index.php应该会弹出fishboy!警告,然后内容为hello,fishboy!!的页面。
  
  我们可以改进一下,不可能每次需要smarty写这么多配置代码吧。
  
  新建文件D:xamppxampphtdocssmarty_connect.php
  
  1
  
  2
  
  3
  
  4
  
  5
  
  6
  
  7
  
  8
  
  9
  
  10
  
  11
  
  //loadsmartylibrary
  
  require('Smarty.class.php');
  
  classsmarty_connectextendsSmarty
  
  {functionsmarty_connect()
  
  {//每次构造自动调用本函数
  
  $this->template_dir='d:/xampp/xampp/htdocs/templates';
  
  $this->config_dir='d:/xampp/xampp/htdocs/config';
  
  $this->cache_dir='d:/xampp/xampp/smarty/cache';
  
  $this->compile_dir='d:/xampp/xampp/smarty/templates_c';
  
  }
  
  }
  
  D:xamppxampphtdocsindex.php改为:
  
  1
  
  2
  
  3
  
  4
  
  require('smarty_connect.php');
  
  $smt=newsmarty_connect;
  
  $smt->assign('name','fishboy!');
  
  $smt->display('index.tpl');
  
  index.tpl文件不变,打开localhost/index.php,出现了同样的输出。
  
  
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-17650-1.html
网站维护教程更新时间:2012-09-21 05:22:56  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer