PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Inc/Mode/Lite/Action.class.php

http://iiccms.googlecode.com/
PHP | 151 lines | 58 code | 8 blank | 85 comment | 8 complexity | 5c77acffd4a5195d9dd911df8e3e4b2b MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // $Id$
  12. /**
  13. +------------------------------------------------------------------------------
  14. * ThinkPHP ????Action?????
  15. +------------------------------------------------------------------------------
  16. */
  17. abstract class Action extends Think
  18. {//?????
  19. protected $tVar = array(); // ??????
  20. /**
  21. +----------------------------------------------------------
  22. * ????
  23. +----------------------------------------------------------
  24. * @access public
  25. +----------------------------------------------------------
  26. */
  27. public function __construct()
  28. {
  29. //??????
  30. if(method_exists($this,'_initialize')) {
  31. $this->_initialize();
  32. }
  33. }
  34. /**
  35. +----------------------------------------------------------
  36. * ???? ????????????
  37. +----------------------------------------------------------
  38. * @access public
  39. +----------------------------------------------------------
  40. * @param string $method ???
  41. * @param array $parms ??
  42. +----------------------------------------------------------
  43. * @return mixed
  44. +----------------------------------------------------------
  45. */
  46. public function __call($method,$parms) {
  47. if(strtolower($method) == strtolower(ACTION_NAME)) {
  48. // ?????_empty?? ???
  49. if(method_exists($this,'_empty')) {
  50. $this->_empty($method,$parms);
  51. }else {
  52. // ????
  53. throw_exception(L('_ERROR_ACTION_').ACTION_NAME);
  54. }
  55. }else{
  56. throw_exception(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_'));
  57. }
  58. }
  59. /**
  60. +----------------------------------------------------------
  61. * ??????
  62. +----------------------------------------------------------
  63. * @access protected
  64. +----------------------------------------------------------
  65. * @param mixed $name
  66. * @param mixed $value
  67. +----------------------------------------------------------
  68. */
  69. protected function assign($name,$value=''){
  70. if(is_array($name)) {
  71. $this->tVar = array_merge($this->tVar,$name);
  72. }elseif(is_object($name)){
  73. foreach($name as $key =>$val)
  74. $this->tVar[$key] = $val;
  75. }else {
  76. $this->tVar[$name] = $value;
  77. }
  78. }
  79. /**
  80. +----------------------------------------------------------
  81. * ????
  82. * ???PHP??
  83. +----------------------------------------------------------
  84. * @access protected
  85. +----------------------------------------------------------
  86. * @param string $templateFile ??????????
  87. * ???? ???????????
  88. * @param string $charset ????
  89. * @param string $contentType ????
  90. +----------------------------------------------------------
  91. * @return void
  92. +----------------------------------------------------------
  93. */
  94. protected function display($templateFile='',$charset='',$contentType='text/html')
  95. {
  96. if(empty($charset)) $charset = C('DEFAULT_CHARSET');
  97. // ??????
  98. header("Content-Type:".$contentType."; charset=".$charset);
  99. header("Cache-control: private"); //??????
  100. //????
  101. ob_start();
  102. ob_implicit_flush(0);
  103. // ????????
  104. $templateFile = $this->parseTemplateFile($templateFile);
  105. // ??????????????
  106. extract($this->tVar, EXTR_OVERWRITE);
  107. // ????PHP??
  108. include $templateFile;
  109. // ???????
  110. $content = ob_get_clean();
  111. echo $content;
  112. }
  113. /**
  114. +----------------------------------------------------------
  115. * ????????
  116. +----------------------------------------------------------
  117. * @access private
  118. +----------------------------------------------------------
  119. * @param string $templateFile ???
  120. +----------------------------------------------------------
  121. * @return string
  122. +----------------------------------------------------------
  123. * @throws ThinkExecption
  124. +----------------------------------------------------------
  125. */
  126. private function parseTemplateFile($templateFile) {
  127. // Lite???????????
  128. if(''==$templateFile) {
  129. // ????????? ????????
  130. $templateFile = TMPL_PATH.'/'.MODULE_NAME.'/'.ACTION_NAME.C('TMPL_TEMPLATE_SUFFIX');
  131. }elseif(strpos($templateFile,':')){
  132. // ???????????
  133. $templateFile = TMPL_PATH.'/'.str_replace(':','/',$templateFile).C('TMPL_TEMPLATE_SUFFIX');
  134. }elseif(!is_file($templateFile)) {
  135. // ?????????????
  136. $templateFile = TMPL_PATH.'/'.MODULE_NAME.'/'.$templateFile.C('TMPL_TEMPLATE_SUFFIX');
  137. }
  138. if(!file_exists_case($templateFile))
  139. throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
  140. return $templateFile;
  141. }
  142. }//?????
  143. ?>