【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了Action.class.php提供大家参考,希望对大家有所帮助!
<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* Think
PHP Action鎺у埗鍣ㄥ熀绫?鎶借薄绫?
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Core
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
abstract class Action extends Base
{//绫诲畾涔夊紑濮?
// Action鎺у埗鍣ㄥ悕绉?
protected $name;
// 妯℃澘瀹炰緥瀵硅薄
protected $tpl;
// 闇瑕佺紦瀛樼殑action
protected $_cacheAction = array();
// 涓婃閿欒淇℃伅
protected $error;
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟 鍙栧緱妯℃澘瀵硅薄瀹炰緥
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function __construct()
{
//瀹炰緥鍖栨ā鏉跨被
$this->tpl = View::getInstance();
$this->name = $this->getActionName();
//鎺у埗鍣ㄥ垵濮嬪寲
$this->_initialize();
}
/**
+----------------------------------------------------------
* 寰楀埌褰撳墠鐨凙ction瀵硅薄鍚嶇О
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
public function getActionName() {
if(empty($this->name)) {
$prefix = C('CONTR_CLASS_PREFIX');
$suffix = C('CONTR_CLASS_SUFFIX');
if($suffix) {
$this->name = substr(substr(get_class($this),strlen($prefix)),0,-strlen($suffix));
}else{
$this->name = substr(get_class($this),strlen($prefix));
}
}
return $this->name;
}
/**
+----------------------------------------------------------
* 鎺у埗鍣ㄥ垵濮嬪寲鎿嶄綔
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
protected function _initialize()
{
//鍒ゆ柇鏄惁鏈堿ction缂撳瓨
if(C('ACTION_CACHE_ON') && in_array(ACTION_NAME,$this->_cacheAction,true)) {
$content = S(md5(__SELF__));
if($content) {
echo $content;
exit;
}
}
return ;
}
protected function isAjax() {
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) {
if(strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])=='
xmlhttprequest')
return true;
}
if(!empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) {
// 鍒ゆ柇Ajax鏂瑰紡鎻愪氦
return true;
}
return false;
}
/**
+----------------------------------------------------------
* 璁板綍涔愯閿?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param mixed $data 鏁版嵁瀵硅薄
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
protected function cacheLockVersion($data) {
$model = D($this->name);
if($model->optimLock) {
if(is_object($data)) $data = get_object_vars($data);
if(isset($data[$model->optimLock]) && isset($data[$model->getPk()])) {
$_SESSION[$model->getModelName().'_'.$data[$model->getPk()].'_lock_version'] = $data[$model->optimLock];
}
}
}
/**
+------