Controller.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. *
  4. */
  5. namespace BaseController;
  6. include ROOT_PATH . '/Config/Services.php';
  7. class Controller {
  8. protected $logger = "";
  9. protected $assignArray = array();
  10. function __construct() {
  11. $post = file_get_contents("php://input");
  12. $post = json_decode($post, 1);
  13. if (count($post) > 0 && count($post) > 0) {
  14. $_POST = array_merge($_POST, $post);
  15. }
  16. global $logger;
  17. $this->logger = $logger;
  18. //获取当前数据源
  19. // $source = lm('setinfo','Sports')->where('infoname','体育比分数据源设置')->value('infocontent');
  20. //
  21. // $this->source = [
  22. // 'source' => $source
  23. // ];
  24. $this->source = require "Config/ControlData.php";
  25. if (method_exists($this, 'beforeInit')) {
  26. $this->beforeInit();
  27. }
  28. if (method_exists($this, 'init')) {
  29. $this->init();
  30. }
  31. }
  32. /**
  33. * 自定义初始化前置功能
  34. *
  35. * @return void
  36. */
  37. function beforeInit(){
  38. }
  39. /**
  40. * 自定义初始化功能
  41. *
  42. * @return void
  43. */
  44. function init(){
  45. }
  46. // protected function Upload($FILES, $A = "", $B = "") {
  47. // $ReturnFILE = array();
  48. // $FILES = array_keys($FILES);
  49. // foreach ($FILES as $K => $V) {
  50. // $FlodName = "Updata/" . date("Y-m-d");
  51. // if (!is_dir($FlodName)) {
  52. // mkdir($FlodName, 777, true);
  53. // }
  54. // if ($_FILES[$FILES[$K]]["error"] > 0) {
  55. // return false;
  56. // }
  57. // $tempEXT = strstr($_FILES[$FILES[$K]]["name"], ".");
  58. // $FileName = date("YmdHis") . UUID() . $tempEXT;
  59. // move_uploaded_file($_FILES[$FILES[$K]]["tmp_name"], "{$FlodName}/" . $FileName);
  60. // $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  61. // $FileName = $FlodName . "/" . $FileName;
  62. // $ReturnFILE[] = $FileName;
  63. // }
  64. // return $ReturnFILE;
  65. // }
  66. // protected function CURL($URI, $Data = "", $header = "") {
  67. // if (is_array($Data)) {
  68. // $Data = json_encode($Data);
  69. // }
  70. // $ch = curl_init();
  71. // $res = curl_setopt($ch, CURLOPT_URL, $URI);
  72. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  73. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  74. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  75. // curl_setopt($ch, CURLOPT_HEADER, 0);
  76. // curl_setopt($ch, CURLOPT_POST, 1);
  77. // curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
  78. // curl_setopt($ch, CURLOPT_HTTPHEADER, array($header, 'Content-Type: application/json'));
  79. // $result = curl_exec($ch);
  80. // curl_close($ch);
  81. // if ($result == NULL) {
  82. // return 0;
  83. // }
  84. // return $result;
  85. // }
  86. protected function assign($key, $value) {
  87. $this->assignArray[$key] = $value;
  88. }
  89. protected function display($View = "") {
  90. $smarty = new \Smarty;
  91. global $ViewPath;
  92. $ViewPath = explode("\\", $ViewPath);
  93. $ViewPath[3] = explode("Controller", $ViewPath[3]);
  94. $ViewPath[3] = $ViewPath[3][0];
  95. $ViewPath[1] = S('CUR_PROJECT');
  96. $ViewPath[3] = S('CUR_CONTROLLER');
  97. $ViewPath[4] = S('CUR_METHOD');
  98. if ($View == "") {
  99. $View = APP_PATH . "/" . $ViewPath[1] . "/View/" . $ViewPath[3] . "/";
  100. }
  101. $smarty->setTemplateDir($View); //设置模板目录
  102. $smarty->setCompileDir(ROOT_PATH . '/Cache/Smarty/compile/');
  103. $smarty->setConfigDir(ROOT_PATH . '/Cache/Smarty/smarty_configs/');
  104. $smarty->setCacheDir(ROOT_PATH . '/Cache/Smarty/cache/');
  105. if (APP_DEBUG) {
  106. //$smarty->debugging = true;
  107. $smarty->caching = false;
  108. $smarty->cache_lifetime = 0;
  109. } else {
  110. //$smarty->debugging = false;
  111. // $smarty->caching = true;
  112. // $smarty->cache_lifetime = 120;
  113. $smarty->caching = false;
  114. $smarty->cache_lifetime = 0;
  115. }
  116. foreach ($this->assignArray as $key => $value) {
  117. $smarty->assign($key, $value);
  118. }
  119. $smarty->display($View . $ViewPath[4] . ".blade.php");
  120. }
  121. }