Discuz教程网

php SMARTY学习手记

[复制链接]
authicon dly 发表于 2011-8-28 11:01:30 | 显示全部楼层 |阅读模式
学习PHP不能不提下SMARTY,作为著名的模板程序,SMARTY自然有其优势。下面是我总结的自己的一点学习心得吧!
=====================================
先在smarty.php.net下载最新smarty
将libs文件夹放在你的WEB目录下,我是放在smarty下的,目录情况如下:e:/smarty/libs
在smarty目录下新建如下文件夹:
templates(这里放你的模板文件,即tpl文件)
configs
templates_c(自动将编译完的文件转成PHP放在这)
cache
然后在wwwroot目录下建立index.php:
  1. <?php
  2. include "smarty/libs/Smarty.class.php";
  3. define('__SITE_ROOT', 'e:/smarty'); // 最後沒有斜線
  4. $tpl = new Smarty();
  5. $tpl->template_dir = __SITE_ROOT . "/templates/";
  6. $tpl->compile_dir = __SITE_ROOT . "/templates_c/";
  7. $tpl->config_dir = __SITE_ROOT . "/configs/";
  8. $tpl->cache_dir = __SITE_ROOT . "/cache/";
  9. //$tpl->left_delimiter = '<{'; 可根据需要更改。
  10. //$tpl->right_delimiter = '}>';
  11. $tpl->assign('name','world!');
  12. $tpl->display('index.tpl')
  13. ?>
复制代码


在template目录下建立index.tpl:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title> New Document </title>
  5. <meta name="Generator" content="EditPlus">
  6. <meta name="Author" content="">
  7. <meta name="Keywords" content="">
  8. <meta name="Description" content="">
  9. </head>

  10. <body>
  11. hello,{$name}~.
  12. </body>
  13. </html>

复制代码



然后本地index.php显示出hello,world!~.





上一篇:DSU_BETA IP策略机 压制并发灌水机的方案
下一篇:php笑谈配置,使用Smarty技术
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 07:13

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表