Controller.php 3.5 KB

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