国内流行的内容管理系统(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.

129 lines
3.5KB

  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) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.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. require_once $modelfile;
  61. }
  62. if (!empty($name) && class_exists($name)) {
  63. return new $name;
  64. }
  65. return false;
  66. }
  67. function Libraries($name = '', $data = '')
  68. {
  69. if (defined('APPNAME')) {
  70. $classfile = 'MY_' . $name . '.class.php';
  71. if (file_exists('../' . APPNAME . '/libraries/' . $classfile)) {
  72. require '../' . APPNAME . '/libraries/' . $classfile;
  73. return new $name($data);
  74. } else {
  75. if (!empty($name) && class_exists($name)) {
  76. return new $name($data);
  77. }
  78. }
  79. return FALSE;
  80. } else {
  81. if (!empty($name) && class_exists($name)) {
  82. return new $name($data);
  83. }
  84. return FALSE;
  85. }
  86. }
  87. //载入helper
  88. function helper($helper, $path)
  89. {
  90. $help_path = $path . '/data/helper/' . $helper . ".helper.php";
  91. if (file_exists($help_path)) {
  92. include_once($help_path);
  93. } else {
  94. exit('Unable to load the requested file: ' . $helper . ".helper.php");
  95. }
  96. }
  97. //显示数据
  98. function Display()
  99. {
  100. $this->tpl->SetObject($this);
  101. $this->tpl->Display();
  102. }
  103. //保存为HTML
  104. function SaveTo($filename)
  105. {
  106. $this->tpl->SetObject($this);
  107. $this->tpl->SaveTo($filename);
  108. }
  109. // 释放资源
  110. function __destruct()
  111. {
  112. unset($this->tpl);
  113. $this->dsql->Close(TRUE);
  114. }
  115. }