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

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