集思博客

集思博客,(www.gisblogs.net)用心记录我的成长历程,留下技术的沉淀……

« Smarty安装和入门教程在mysql 中修改表名的SQL语句 »

Smarty安装和入门教程二

Smarty安装:
下载并解压Smarty2.6.5,将其smarty文件夹(注意含有 3 个 class.php  + 1 个 debug.tpl + 1 个 plugin + 1 个 core )复制到主程序文件夹下,然后在同一位置建configs,includes,modules,templates,templates_c五个文件夹.Linux下,将 templates_c 的权限变更为 777 .


 

Smarty测试。
index.tpl放到templates文件夹下,
内容为:
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title><{$title}></title>
  </head>
  <body>
  <{$content}>
  </body>
  </html>


 

index.php放到主程序文件夹下,
如下:
 <?php
 
   include("./class/Smarty.class.php"); //包含smarty类文件
      $smarty = new Smarty();  //建立smarty实例对象$smarty
     $smarty->template_dir = './templates/';
   $smarty->compile_dir  = './templates_c/';
   $smarty->config_dir   = './configs/';
   $smarty->cache_dir    = './cache/';
   $smarty->caching      = false;

      $smarty->left_delimiter = "<{";
      $smarty->right_delimiter = "}>";
   


 

      $smarty->assign("title", "垃圾"); //进行模板变量替换
   $smarty->assign("content","测试用的网页内容00");
     
      //编译并显示位于./templates下的index.tpl模板
      $smarty->display("index.tpl"); //index.tpl
   ?>


 

在ie输入 http://localhost/index.php测试

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80605 Code detection by Codefense  theme by BokeZhuti

Copyright 2007-2008 集思博客 www.gisblogs.net 备案号:粤ICP备07051728号 联系QQ:6390514