免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2156 | 回复: 12
打印 上一主题 下一主题

SimpleT 的作者原来就是 Harry Fuecks [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-22 15:57 |只看该作者 |倒序浏览
这个template有人用吗?


  1. <?php
  2. /* $Id$ */
  3. // Switches caching behaviour on/off
  4. if ( !defined('SIMPLET_CACHE') )
  5.     define ('SIMPLET_CACHE','1');

  6. // Include SimpleTemplate
  7. require_once('SIMPLET/Simplet.php');

  8. // Setup PEAR::Cache_Lite
  9. $cacheOptions = array(
  10.     'cacheDir' =>; 'cache/',
  11. );
  12. $cache = & new Cache_Lite($cacheOptions);

  13. // Create a ViewHandler for the template, passing it
  14. // Cache_Lite, the name of the template file and a cache
  15. // expiry time in seconds
  16. $view = new SimpleT_ViewHandler($cache,'flush.php',60);

  17. // Flush the cache
  18. if ( isset($_GET['flush']) && $_GET['flush'] == 'true' ) {
  19.     $view->;flush();
  20.     header ('Location: '.$_SERVER['PHP_SELF']);
  21.     exit();
  22. }

  23. // If the view isn't cached, build it...
  24. if ( !$view->;isCached() ) {

  25.     // Instantiate the Binder: this class "parses" the template
  26.     $binder = new SimpleT_Binder();

  27.     // Create an array to store data to be bound to template
  28.     $model = array();

  29.     // Add some simple "Model" data to BindData
  30.     $model['title'] = 'A cache flush example';
  31.     $model['message'] = 'Hello World!';
  32.     $model['time'] = date ('H:i:s');
  33.     $model['flush_url'] = 'flush_controller.php?flush=true';

  34.     // Pass the "View" object to the binder
  35.     $binder->;setView($view);

  36.     // Pass the "Model" object to the binder
  37.     $binder->;setData($model);

  38.     // Bind the "Model" to the "View"
  39.     $binder->;bind();

  40. }

  41. // Get the output from the View
  42. $output = $view->;toString();

  43. echo ( $output );
  44. ?>;

复制代码

论坛徽章:
0
2 [报告]
发表于 2004-06-22 17:43 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

看样子不错

论坛徽章:
0
3 [报告]
发表于 2004-06-22 22:50 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

没看出什么特别的地方

论坛徽章:
0
4 [报告]
发表于 2004-06-23 08:41 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

上面是一个用法的例子!
这个模板跟Brian Lozier的那个一样都是php based。
wact的template view里提到过!

论坛徽章:
0
5 [报告]
发表于 2004-06-23 08:53 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

这个模板有些什么优势?

论坛徽章:
0
6 [报告]
发表于 2004-06-23 09:14 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

大概看了一下文档

这个模板实际上就是将绑定数据这个操作独立出来做成了另一个class,而模板文件处理和缓存管理就是另一个class。
总的来说相对于 Brian E. Lozier (brian@massassi.net) 的模版引擎没有什么优势。

论坛徽章:
0
7 [报告]
发表于 2004-06-23 09:59 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

再来一个。也是Harry Fuecks的

  1. <?php
  2. /* index.php */

  3. /* Include fictional data access class */
  4. include("classes/Dao.php");

  5. /* Connect to database */
  6. $dao=new Dao ("dbhost","dbname","dbuser","dbpass" );

  7. /* Include awesome template engine */
  8. include("classes/AwesomeTemplateEngine.class.php");

  9. /* Fire up template engine */
  10. $path = "/home/user/www/templates/";
  11. $awesomeTemplateEngine= new AwesomeTemplateEngine($path);

  12. $dataObject=$dao->;fetchObject("SELECT name, email, signature FROM users ORDER BY name");

  13. $awesomeTemplateEngine->;parseTemplate($dataObject,"viewuser_template.php");
  14. ?>;

复制代码

  1. <?php
  2. /* viewuser_template.php */
  3. ?>;
  4. <html>;
  5. <head>;
  6. <title>;View User</title>;
  7. </head>;
  8. <body>;
  9. <?php
  10. foreach ($dataObject as $dataChild) {
  11. ?>;
  12. <p>;Name:<?php echo ($dataChild->;name); ?>;
  13. <p>;Email:<?php echo ($dataChild->;email); ?>;
  14. <p>;Signature:<?php echo ($dataChild->;name); ?>;
  15. <?php
  16. }
  17. ?>;
  18. </body>;
  19. </html>;

复制代码

And the Awesome Template engine...

PHP:

  1. <?php
  2. /* AwesomeTemplateEngine.class.php */
  3. class AwesomeTemplateEngine {
  4.     var $templatePath;
  5.     function AwesomeTemplateEngine($templatePath) {
  6.         $this->;templatePath=$templatePath;
  7.     }
  8.     function parseTemplate($dataObject,$template) {
  9.         include($this->;templatePath.$template);
  10.     }
  11. }
  12. ?>;
复制代码

论坛徽章:
0
8 [报告]
发表于 2004-06-23 10:09 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

<?php
echo 'That's end';
?>;
还是这个直截了当!
longnetpro 该用户已被删除
9 [报告]
发表于 2004-06-23 13:37 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
10 [报告]
发表于 2004-06-23 17:01 |只看该作者

SimpleT 的作者原来就是 Harry Fuecks

<?php
echo "That's all";
?>;

看来离开zend ide就不行呀!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP