TemplateSmarty.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // $Id$
  12. /**
  13. +------------------------------------------------------------------------------
  14. * Smarty模板引擎解析类
  15. +------------------------------------------------------------------------------
  16. * @category Think
  17. * @package Think
  18. * @subpackage Util
  19. * @author liu21st <liu21st@gmail.com>
  20. * @version $Id$
  21. +------------------------------------------------------------------------------
  22. */
  23. class TemplateSmarty
  24. {
  25. /**
  26. +----------------------------------------------------------
  27. * 渲染模板输出
  28. +----------------------------------------------------------
  29. * @access public
  30. +----------------------------------------------------------
  31. * @param string $templateFile 模板文件名
  32. * @param array $var 模板变量
  33. * @param string $charset 模板输出字符集
  34. +----------------------------------------------------------
  35. * @return void
  36. +----------------------------------------------------------
  37. */
  38. public function fetch($templateFile,$var,$charset) {
  39. $templateFile=substr($templateFile,strlen(TMPL_PATH));
  40. vendor('Smarty.Smarty#class');
  41. $tpl = new Smarty();
  42. if(C('TMPL_ENGINE_CONFIG')) {
  43. $config = C('TMPL_ENGINE_CONFIG');
  44. foreach ($config as $key=>$val){
  45. $tpl->{$key} = $val;
  46. }
  47. }else{
  48. $tpl->caching = C('TMPL_CACHE_ON');
  49. $tpl->template_dir = TMPL_PATH;
  50. $tpl->compile_dir = CACHE_PATH ;
  51. $tpl->cache_dir = TEMP_PATH ;
  52. }
  53. $tpl->assign($var);
  54. $tpl->display($templateFile);
  55. }
  56. }
  57. ?>