国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.4KB

  1. <?php if(!defined('DEDEINC')) exit("Request Error!");
  2. /**
  3. * 织梦控制器基类
  4. *
  5. * @version $Id: control.class.php 1 10:33 2010年7月6日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2007 - 2019, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. require_once(DEDEINC."/dedetemplate.class.php");
  12. class Control
  13. {
  14. var $tpl;
  15. var $dsql;
  16. var $style='default';
  17. var $_helpers = array();
  18. var $apptpl = '../templates/';
  19. function __construct()
  20. {
  21. $this->Control();
  22. }
  23. // 析构函数
  24. function Control()
  25. {
  26. global $dsql;
  27. $this->tpl = isset($this->tpl)? $this->tpl : new DedeTemplate();
  28. $sqltype = "DedeSql";
  29. if ($GLOBALS['cfg_mysql_type'] == 'mysqli' && function_exists("mysqli_init")) $sqltype = "DedeSql";
  30. else $sqltype = "DedeSqli";
  31. $this->dsql = isset($dsql)? $dsql : new $sqltype(FALSE);
  32. }
  33. //设置模板
  34. //如果想要使用模板中指定的pagesize,必须在调用模板后才调用 SetSource($sql)
  35. function SetTemplate($tplfile)
  36. {
  37. $tplfile = DEDEAPPTPL.'/'.$this->style.'/'.$tplfile;
  38. $this->tpl->LoadTemplate($tplfile);
  39. }
  40. function SetTemplet($tplfile)
  41. {
  42. $tplfile = DEDEAPPTPL.'/'.$this->style.'/'.$tplfile;
  43. $this->tpl->LoadTemplate($tplfile);
  44. }
  45. //设置/获取文档相关的各种变量
  46. function SetVar($k, $v)
  47. {
  48. $this->tpl->Assign($k, $v);
  49. }
  50. function GetVar($k)
  51. {
  52. global $_vars;
  53. return isset($_vars[$k]) ? $_vars[$k] : '';
  54. }
  55. function Model($name='')
  56. {
  57. $name = preg_replace("#[^\w]#", "", $name);
  58. $modelfile = DEDEMODEL.'/'.$name.'.php';
  59. if (file_exists($modelfile))
  60. {
  61. require_once $modelfile;
  62. }
  63. if (!empty($name) && class_exists($name))
  64. {
  65. return new $name;
  66. }
  67. return false;
  68. }
  69. function Libraries($name='',$data = '')
  70. {
  71. if(defined('APPNAME'))
  72. {
  73. $classfile = 'MY_'.$name.'.class.php';
  74. if ( file_exists ( '../'.APPNAME.'/libraries/'.$classfile ) )
  75. {
  76. require '../'.APPNAME.'/libraries/'.$classfile;
  77. return new $name($data);
  78. }else{
  79. if (!empty($name) && class_exists($name))
  80. {
  81. return new $name($data);
  82. }
  83. }
  84. return FALSE;
  85. }else{
  86. if (!empty($name) && class_exists($name))
  87. {
  88. return new $name($data);
  89. }
  90. return FALSE;
  91. }
  92. }
  93. //载入helper
  94. function helper($helper = "",$path)
  95. {
  96. $help_path = $path.'/data/helper/'.$helper.".helper.php";
  97. if (file_exists($help_path))
  98. {
  99. include_once($help_path);
  100. }else{
  101. exit('Unable to load the requested file: '.$helper.".helper.php");
  102. }
  103. }
  104. //显示数据
  105. function Display()
  106. {
  107. $this->tpl->SetObject($this);
  108. $this->tpl->Display();
  109. }
  110. //保存为HTML
  111. function SaveTo($filename)
  112. {
  113. $this->tpl->SetObject($this);
  114. $this->tpl->SaveTo($filename);
  115. }
  116. // 释放资源
  117. function __destruct() {
  118. unset($this->tpl);
  119. $this->dsql->Close(TRUE);
  120. }
  121. }