/Inc/Mode/Lite/Action.class.php
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
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: liu21st <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // $Id$
-
- /**
- +------------------------------------------------------------------------------
- * ThinkPHP ????Action?????
- +------------------------------------------------------------------------------
- */
- abstract class Action extends Think
- {//?????
-
- protected $tVar = array(); // ??????
-
- /**
- +----------------------------------------------------------
- * ????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- */
- public function __construct()
- {
- //??????
- if(method_exists($this,'_initialize')) {
- $this->_initialize();
- }
- }
-
- /**
- +----------------------------------------------------------
- * ???? ????????????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @param string $method ???
- * @param array $parms ??
- +----------------------------------------------------------
- * @return mixed
- +----------------------------------------------------------
- */
- public function __call($method,$parms) {
- if(strtolower($method) == strtolower(ACTION_NAME)) {
- // ?????_empty?? ???
- if(method_exists($this,'_empty')) {
- $this->_empty($method,$parms);
- }else {
- // ????
- throw_exception(L('_ERROR_ACTION_').ACTION_NAME);
- }
- }else{
- throw_exception(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_'));
- }
- }
-
- /**
- +----------------------------------------------------------
- * ??????
- +----------------------------------------------------------
- * @access protected
- +----------------------------------------------------------
- * @param mixed $name
- * @param mixed $value
- +----------------------------------------------------------
- */
- protected function assign($name,$value=''){
- if(is_array($name)) {
- $this->tVar = array_merge($this->tVar,$name);
- }elseif(is_object($name)){
- foreach($name as $key =>$val)
- $this->tVar[$key] = $val;
- }else {
- $this->tVar[$name] = $value;
- }
- }
-
- /**
- +----------------------------------------------------------
- * ????
- * ???PHP??
- +----------------------------------------------------------
- * @access protected
- +----------------------------------------------------------
- * @param string $templateFile ??????????
- * ???? ???????????
- * @param string $charset ????
- * @param string $contentType ????
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- */
- protected function display($templateFile='',$charset='',$contentType='text/html')
- {
- if(empty($charset)) $charset = C('DEFAULT_CHARSET');
- // ??????
- header("Content-Type:".$contentType."; charset=".$charset);
- header("Cache-control: private"); //??????
- //????
- ob_start();
- ob_implicit_flush(0);
- // ????????
- $templateFile = $this->parseTemplateFile($templateFile);
- // ??????????????
- extract($this->tVar, EXTR_OVERWRITE);
- // ????PHP??
- include $templateFile;
- // ???????
- $content = ob_get_clean();
- echo $content;
- }
-
- /**
- +----------------------------------------------------------
- * ????????
- +----------------------------------------------------------
- * @access private
- +----------------------------------------------------------
- * @param string $templateFile ???
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- private function parseTemplateFile($templateFile) {
- // Lite???????????
- if(''==$templateFile) {
- // ????????? ????????
- $templateFile = TMPL_PATH.'/'.MODULE_NAME.'/'.ACTION_NAME.C('TMPL_TEMPLATE_SUFFIX');
- }elseif(strpos($templateFile,':')){
- // ???????????
- $templateFile = TMPL_PATH.'/'.str_replace(':','/',$templateFile).C('TMPL_TEMPLATE_SUFFIX');
- }elseif(!is_file($templateFile)) {
- // ?????????????
- $templateFile = TMPL_PATH.'/'.MODULE_NAME.'/'.$templateFile.C('TMPL_TEMPLATE_SUFFIX');
- }
- if(!file_exists_case($templateFile))
- throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
- return $templateFile;
- }
-
- }//?????
- ?>