diff --git a/Think/Behavior/LocationTemplate.php b/Think/Behavior/LocationTemplate.php
index 6a9d7b11..149c75e4 100644
--- a/Think/Behavior/LocationTemplate.php
+++ b/Think/Behavior/LocationTemplate.php
@@ -44,7 +44,7 @@ class LocationTemplate {
}
$templateFile = MODULE_PATH.'view/'.$template.'.html';
if(!is_file($templateFile))
- throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
+ E(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
return $templateFile;
}
}
\ No newline at end of file
diff --git a/Think/Config.php b/Think/Config.php
index e4573cbb..511e65ae 100644
--- a/Think/Config.php
+++ b/Think/Config.php
@@ -24,7 +24,7 @@ class Config {
if(class_exists($class)) {
self::set((new $class())->parse($config),'',$range);
}else{
- throw_exception('class not exists: ' . $class);
+ E('class not exists: ' . $class);
}
}
diff --git a/Think/Db/Driver.php b/Think/Db/Driver.php
index 1509b96a..3de84833 100644
--- a/Think/Db/Driver.php
+++ b/Think/Db/Driver.php
@@ -85,7 +85,7 @@ abstract class Driver {
}
$this->linkID[$linkNum] = new PDO( $config['dsn'], $config['username'], $config['password'],$config['params']);
}catch (\PDOException $e) {
- throw_exception($e->getMessage());
+ E($e->getMessage());
}
if(!empty($config['charset'])) {
$this->linkID[$linkNum]->exec('SET NAMES '.$config['charset']);
@@ -121,7 +121,7 @@ abstract class Driver {
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if(false === $this->PDOStatement)
- throw_exception($this->error());
+ E($this->error());
$result = $this->PDOStatement->execute($bind);
// 调试结束
$this->debug(false);
@@ -150,7 +150,7 @@ abstract class Driver {
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if(false === $this->PDOStatement) {
- throw_exception($this->error());
+ E($this->error());
}
$result = $this->PDOStatement->execute($bind);
$this->debug(false);
@@ -421,7 +421,7 @@ abstract class Driver {
}else{
// 查询字段的安全过滤
if(!preg_match('/^[A-Z_\|\&\-.a-z0-9\(\)\,]+$/',trim($key))){
- throw_exception(L('_EXPRESS_ERROR_').':'.$key);
+ E(L('_EXPRESS_ERROR_').':'.$key);
}
// 多条件支持
$multi = is_array($val) && isset($val['_multi']);
@@ -490,7 +490,7 @@ abstract class Driver {
$data = is_string($val[1])? explode(',',$val[1]):$val[1];
$whereStr .= ' ('.$key.' '.strtoupper($val[0]).' '.$this->parseValue($data[0]).' AND '.$this->parseValue($data[1]).' )';
}else{
- throw_exception(L('_EXPRESS_ERROR_').':'.$val[0]);
+ E(L('_EXPRESS_ERROR_').':'.$val[0]);
}
}else {
$count = count($val);
diff --git a/Think/Db/Driver/Oracle.php b/Think/Db/Driver/Oracle.php
index e3661e16..d7bbc389 100644
--- a/Think/Db/Driver/Oracle.php
+++ b/Think/Db/Driver/Oracle.php
@@ -41,13 +41,13 @@ class Oracle extends Driver{
if ( !empty($this->PDOStatement) ) $this->free();
$this->executeTimes++;
// 记录开始执行时间
- Debug::remark('queryStartTime','time');
+ $this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if(false === $this->PDOStatement) {
- throw_exception($this->error());
+ E($this->error());
}
$result = $this->PDOStatement->execute($bind);
- $this->debug();
+ $this->debug(false);
if ( false === $result) {
$this->error();
return false;
diff --git a/Think/Db/Lite.php b/Think/Db/Lite.php
index 21878999..3ca8f10d 100644
--- a/Think/Db/Lite.php
+++ b/Think/Db/Lite.php
@@ -82,7 +82,7 @@ class Lite {
}
$this->linkID[$linkNum] = new PDO( $config['dsn'], $config['username'], $config['password'],$config['params']);
}catch (\PDOException $e) {
- throw_exception($e->getMessage());
+ E($e->getMessage());
}
if(!empty($config['charset'])) {
$this->linkID[$linkNum]->exec('SET NAMES '.$config['charset']);
@@ -117,7 +117,7 @@ class Lite {
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if(false === $this->PDOStatement)
- throw_exception($this->error());
+ E($this->error());
$result = $this->PDOStatement->execute($bind);
$this->debug(false);
if ( false === $result ) {
@@ -145,7 +145,7 @@ class Lite {
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if(false === $this->PDOStatement) {
- throw_exception($this->error());
+ E($this->error());
}
$result = $this->PDOStatement->execute($bind);
$this->debug(false);
diff --git a/Think/Exception.php b/Think/Exception.php
index 1f68d62b..7edc1c30 100644
--- a/Think/Exception.php
+++ b/Think/Exception.php
@@ -11,70 +11,4 @@
// $Id$
namespace Think;
class Exception extends \Exception {
-
- /**
- * 异常类型
- * @var string
- * @access private
- */
- private $type;
-
- // 是否存在多余调试信息
- private $extra;
-
- /**
- * 架构函数
- * @access public
- * @param string $message 异常信息
- */
- public function __construct($message,$code=0,$extra=false) {
- parent::__construct($message,$code);
- $this->type = get_class($this);
- $this->extra = $extra;
- }
-
- /**
- * 异常输出 所有异常处理类均通过__toString方法输出错误
- * 每次异常都会写入系统日志
- * 该方法可以被子类重载
- * @access public
- * @return array
- */
- public function __toString() {
- $trace = $this->getTrace();
- if($this->extra)
- // 通过throw_exception抛出的异常要去掉多余的调试信息
- array_shift($trace);
- $this->class = isset($trace[0]['class'])?$trace[0]['class']:'';
- $this->function = isset($trace[0]['function'])?$trace[0]['function']:'';
- $this->file = $trace[0]['file'];
- $this->line = $trace[0]['line'];
- $file = file($this->file);
- $traceInfo = '';
- $time = date('y-m-d H:i:m');
- foreach($trace as $t) {
- $traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') ';
- $traceInfo .= $t['class'].$t['type'].$t['function'].'(';
- $traceInfo .= implode(', ', $t['args']);
- $traceInfo .=")\n";
- }
- $error['message'] = $this->message;
- $error['type'] = $this->type;
- $error['detail'] = ($this->line-2).': '.$file[$this->line-3];
- $error['detail'] .= ($this->line-1).': '.$file[$this->line-2];
- $error['detail'] .= ''.($this->line).': '.$file[$this->line-1].'';
- $error['detail'] .= ($this->line+1).': '.$file[$this->line];
- $error['detail'] .= ($this->line+2).': '.$file[$this->line+1];
- $error['class'] = $this->class;
- $error['function'] = $this->function;
- $error['file'] = $this->file;
- $error['line'] = $this->line;
- $error['trace'] = $traceInfo;
-
- // 记录 Exception 日志
- if(C('LOG_EXCEPTION_RECORD')) {
- ThinkLog::Write('('.$this->type.') '.$this->message);
- }
- return $error ;
- }
}
\ No newline at end of file
diff --git a/Think/Image/Driver/Imagick.php b/Think/Image/Driver/Imagick.php
index 528b2dd9..b9387b0c 100644
--- a/Think/Image/Driver/Imagick.php
+++ b/Think/Image/Driver/Imagick.php
@@ -30,7 +30,7 @@ class Imagick{
*/
public function __construct($imgname = null) {
if ( !extension_loaded('Imagick') ) {
- throw_exception(__('_NOT_SUPPERT_').':Imagick');
+ E(L('_NOT_SUPPERT_').':Imagick');
}
$imgname && $this->open($imgname);
}
diff --git a/Think/Log.php b/Think/Log.php
index 22965dde..a79b3004 100644
--- a/Think/Log.php
+++ b/Think/Log.php
@@ -25,7 +25,7 @@ class Log {
return self::$handler;
}else {
// 类没有定义
- throw_exception(Lang::get('_CLASS_NOT_EXIST_').': ' . $class);
+ E(L('_CLASS_NOT_EXIST_').': ' . $class);
}
}
}
diff --git a/Think/Model.php b/Think/Model.php
index 11af7641..3d69f6d9 100644
--- a/Think/Model.php
+++ b/Think/Model.php
@@ -960,7 +960,7 @@ class Model {
}elseif(is_string($data)){
parse_str($data,$data);
}elseif(!is_array($data)){
- throw_exception(L('_DATA_TYPE_INVALID_'));
+ E(L('_DATA_TYPE_INVALID_'));
}
$this->data = $data;
return $this;
@@ -1007,7 +1007,7 @@ class Model {
$options = $union;
}
}else{
- throw_exception(L('_DATA_TYPE_INVALID_'));
+ E(L('_DATA_TYPE_INVALID_'));
}
$this->options['union'][] = $options;
return $this;
diff --git a/Think/Oauth/Driver/Diandian.php b/Think/Oauth/Driver/Diandian.php
index 1e9f7f04..bf8cb589 100644
--- a/Think/Oauth/Driver/Diandian.php
+++ b/Think/Oauth/Driver/Diandian.php
@@ -85,7 +85,7 @@ class Diandian extends Driver{
$userInfo['avatar'] = "https://api.diandian.com/v1/blog/{$data['response']['blogs'][0]['blogUuid']}/avatar/144";
return $userInfo;
} else {
- throw_exception("获取点点用户信息失败:{$data}");
+ E("获取点点用户信息失败:{$data}");
}
}
diff --git a/Think/Oauth/Driver/Douban.php b/Think/Oauth/Driver/Douban.php
index c52565b2..e9e1faa7 100644
--- a/Think/Oauth/Driver/Douban.php
+++ b/Think/Oauth/Driver/Douban.php
@@ -83,7 +83,7 @@ class Douban extends Driver{
$userInfo['avatar'] = $data['avatar'];
return $userInfo;
} else {
- throw_exception("获取豆瓣用户信息失败:{$data['msg']}");
+ E("获取豆瓣用户信息失败:{$data['msg']}");
}
}
diff --git a/Think/Oauth/Driver/Github.php b/Think/Oauth/Driver/Github.php
index c3298d0d..e037c994 100644
--- a/Think/Oauth/Driver/Github.php
+++ b/Think/Oauth/Driver/Github.php
@@ -85,7 +85,7 @@ class Github extends Driver{
$userInfo['avatar'] = $data['avatar_url'];
return $userInfo;
} else {
- throw_exception("获取Github用户信息失败:{$data}");
+ E("获取Github用户信息失败:{$data}");
}
}
diff --git a/Think/Oauth/Driver/Google.php b/Think/Oauth/Driver/Google.php
index 64cee8f4..d5fe8e4c 100644
--- a/Think/Oauth/Driver/Google.php
+++ b/Think/Oauth/Driver/Google.php
@@ -91,7 +91,7 @@ class Google extends Driver{
$userInfo['avatar'] = $data['picture'];
return $userInfo;
} else {
- throw_exception("获取Google用户信息失败:{$data}");
+ E("获取Google用户信息失败:{$data}");
}
}
diff --git a/Think/Oauth/Driver/Kaixin.php b/Think/Oauth/Driver/Kaixin.php
index 2165a205..dfac5485 100644
--- a/Think/Oauth/Driver/Kaixin.php
+++ b/Think/Oauth/Driver/Kaixin.php
@@ -86,7 +86,7 @@ class Kaixin extends Driver{
$userInfo['avatar'] = $data['logo50'];
return $userInfo;
} else {
- throw_exception("获取开心网用户信息失败:{$data['error']}");
+ E("获取开心网用户信息失败:{$data['error']}");
}
}
diff --git a/Think/Oauth/Driver/Msn.php b/Think/Oauth/Driver/Msn.php
index 0a658d6a..429e2c61 100644
--- a/Think/Oauth/Driver/Msn.php
+++ b/Think/Oauth/Driver/Msn.php
@@ -92,7 +92,7 @@ class Msn extends Driver{
$userInfo['avatar'] = '微软暂未提供头像URL,请通过 me/picture 接口下载';
return $userInfo;
} else {
- throw_exception("获取msn用户信息失败:{$data}");
+ E("获取msn用户信息失败:{$data}");
}
}
diff --git a/Think/Oauth/Driver/Qq.php b/Think/Oauth/Driver/Qq.php
index c93b2d3c..0b1b270d 100644
--- a/Think/Oauth/Driver/Qq.php
+++ b/Think/Oauth/Driver/Qq.php
@@ -95,7 +95,7 @@ class Qq extends Driver{
$userInfo['avatar'] = $data['figureurl_2'];
return $userInfo;
} else {
- throw_exception("获取腾讯QQ用户信息失败:{$data['msg']}");
+ E("获取腾讯QQ用户信息失败:{$data['msg']}");
}
}
}
\ No newline at end of file
diff --git a/Think/Oauth/Driver/Renren.php b/Think/Oauth/Driver/Renren.php
index b48f7994..696567b7 100644
--- a/Think/Oauth/Driver/Renren.php
+++ b/Think/Oauth/Driver/Renren.php
@@ -109,7 +109,7 @@ class Renren extends Driver{
$userInfo['avatar'] = $data[0]['headurl'];
return $userInfo;
} else {
- throw_exception("获取人人网用户信息失败:{$data['error_msg']}");
+ E("获取人人网用户信息失败:{$data['error_msg']}");
}
}
}
\ No newline at end of file
diff --git a/Think/Oauth/Driver/Sina.php b/Think/Oauth/Driver/Sina.php
index b2ac75a8..da2165e5 100644
--- a/Think/Oauth/Driver/Sina.php
+++ b/Think/Oauth/Driver/Sina.php
@@ -85,7 +85,7 @@ class Sina extends Driver{
$userInfo['avatar'] = $data[0]['headurl'];
return $userInfo;
} else {
- throw_exception("获取人人网用户信息失败:{$data['error_msg']}");
+ E("获取人人网用户信息失败:{$data['error_msg']}");
}
}
diff --git a/Think/Oauth/Driver/Sohu.php b/Think/Oauth/Driver/Sohu.php
index e0bceb13..9f652461 100644
--- a/Think/Oauth/Driver/Sohu.php
+++ b/Think/Oauth/Driver/Sohu.php
@@ -85,7 +85,7 @@ class Sohu extends Driver{
$userInfo['avatar'] = $data['data']['icon'];
return $userInfo;
} else {
- throw_exception("获取搜狐用户信息失败:{$data['message']}");
+ E("获取搜狐用户信息失败:{$data['message']}");
}
}
diff --git a/Think/Oauth/Driver/T163.php b/Think/Oauth/Driver/T163.php
index 345a1fd0..6de83651 100644
--- a/Think/Oauth/Driver/T163.php
+++ b/Think/Oauth/Driver/T163.php
@@ -87,7 +87,7 @@ class T163 extends Driver{
$userInfo['avatar'] = str_replace('w=48&h=48', 'w=180&h=180', $data['profile_image_url']);
return $userInfo;
} else {
- throw_exception("获取网易微博用户信息失败:{$data['error']}");
+ E("获取网易微博用户信息失败:{$data['error']}");
}
}
diff --git a/Think/Oauth/Driver/Taobao.php b/Think/Oauth/Driver/Taobao.php
index 4109157f..f257b9b0 100644
--- a/Think/Oauth/Driver/Taobao.php
+++ b/Think/Oauth/Driver/Taobao.php
@@ -89,7 +89,7 @@ class Taobao extends Driver{
$userInfo['avatar'] = $user['avatar'];
return $userInfo;
} else {
- throw_exception("获取淘宝网用户信息失败:{$data['error_response']['msg']}");
+ E("获取淘宝网用户信息失败:{$data['error_response']['msg']}");
}
}
diff --git a/Think/Oauth/Driver/Tencent.php b/Think/Oauth/Driver/Tencent.php
index 1be8b330..eab8ec11 100644
--- a/Think/Oauth/Driver/Tencent.php
+++ b/Think/Oauth/Driver/Tencent.php
@@ -90,7 +90,7 @@ class Tencent extends Driver{
$userInfo['avatar'] = $data[0]['headurl'];
return $userInfo;
} else {
- throw_exception("获取人人网用户信息失败:{$data['error_msg']}");
+ E("获取人人网用户信息失败:{$data['error_msg']}");
}
}
diff --git a/Think/Oauth/Driver/X360.php b/Think/Oauth/Driver/X360.php
index 48c6d2c0..43938806 100644
--- a/Think/Oauth/Driver/X360.php
+++ b/Think/Oauth/Driver/X360.php
@@ -85,7 +85,7 @@ class X360 extends Driver{
$userInfo['avatar'] = $data['avatar'];
return $userInfo;
} else {
- throw_exception("获取360用户信息失败:{$data['error']}");
+ E("获取360用户信息失败:{$data['error']}");
}
}
diff --git a/Think/Rest.php b/Think/Rest.php
index 594ba5ab..d88153ff 100644
--- a/Think/Rest.php
+++ b/Think/Rest.php
@@ -67,7 +67,7 @@ abstract class Rest {
$this->$fun();
}else{
// 抛出异常
- throw_exception(L('_ERROR_ACTION_:').ACTION_NAME);
+ E(L('_ERROR_ACTION_:').ACTION_NAME);
}
}
diff --git a/Think/Session.php b/Think/Session.php
index 3990abf3..72c311a4 100644
--- a/Think/Session.php
+++ b/Think/Session.php
@@ -56,7 +56,7 @@ class Session {
$hander->execute();
}else {
// 类没有定义
- throw_exception(Lang::get('_CLASS_NOT_EXIST_').': ' . $class);
+ E(L('_CLASS_NOT_EXIST_').': ' . $class);
}
}
// 启动session
diff --git a/Think/Template/Driver/File.php b/Think/Template/Driver/File.php
index e83906c8..62423d98 100644
--- a/Think/Template/Driver/File.php
+++ b/Think/Template/Driver/File.php
@@ -20,7 +20,7 @@ class File {
mkdir($dir,0755,true);
// 生成模板缓存文件
if( false === file_put_contents($cacheFile,$content))
- throw_exception('_CACHE_WRITE_ERROR_:'.$cacheFile);
+ E('_CACHE_WRITE_ERROR_:'.$cacheFile);
}
// 读取编译编译
diff --git a/base.php b/base.php
index 8224f1ab..a8df6778 100644
--- a/base.php
+++ b/base.php
@@ -40,71 +40,35 @@ define('NOW_TIME', $_SERVER['REQUEST_TIME']);
// 获取多语言变量
function L($name){
- return \Think\Lang::get($name);
+ return Think\Lang::get($name);
}
// 获取配置参数
function C($name='',$range='') {
- return \Think\Config::get($name,$range);
+ return Think\Config::get($name,$range);
}
-// 获取输入数据
-function I($key,$default,$filter) {
+// 获取输入数据 支持默认值和过滤
+function I($key,$default='',$filter='') {
if(strpos($key,'.')) { // 指定参数来源
list($method,$key) = explode('.',$key);
}else{ // 默认为自动判断
$method = 'param';
}
- return \Think\Input::$method($key,$filter,$default);
+ return Think\Input::$method($key,$filter,$default);
}
/**
- * 记录和统计时间(微秒)和内存使用情况
- * 使用方法:
- *
- * G('begin'); // 记录开始标记位
- * // ... 区间运行代码
- * G('end'); // 记录结束标签位
- * echo G('begin','end',6); // 统计区间运行时间 精确到小数后6位
- * echo G('begin','end','m'); // 统计区间内存使用情况
- * 如果end标记位没有定义,则会自动以当前作为标记位
- * 其中统计内存使用需要 MEMORY_LIMIT_ON 常量为true才有效
- *
- * @param string $start 开始标签
- * @param string $end 结束标签
- * @param integer|string $dec 小数位或者m
- * @return mixed
+ * 记录时间(微秒)和内存使用情况
+ * @param string $label 记录标签
+ * @return void
*/
-function G($name) {
- Think\Debug::remark($name);
+function G($label) {
+ Think\Debug::remark($label);
}
/**
- * 设置和获取统计数据
- * 使用方法:
- *
- * N('db',1); // 记录数据库操作次数
- * N('read',1); // 记录读取次数
- * echo N('db'); // 获取当前页面数据库的所有操作次数
- * echo N('read'); // 获取当前页面读取次数
- *
- * @param string $key 标识位置
- * @param integer $step 步进值
- * @return mixed
- */
-function N($key, $step=0) {
- static $_num = array();
- if (!isset($_num[$key])) {
- $_num[$key] = 0;
- }
- if (empty($step))
- return $_num[$key];
- else
- $_num[$key] = $_num[$key] + (int) $step;
-}
-
-/**
- * M函数用于实例化一个没有模型文件的Model
+ * 实例化一个没有模型文件的Model
* @param string $name Model名称 支持指定基础模型 例如 MongoModel:User
* @param string $tablePrefix 表前缀
* @param mixed $connection 数据库连接信息
@@ -115,27 +79,27 @@ function M($name='', $tablePrefix='',$connection='') {
}
/**
- * D函数用于实例化Model
+ * 实例化Model
* @param string $name Model名称
* @param string $layer 业务层名称
- * @return ThinkModel
+ * @return object
*/
function D($name='',$layer='model') {
return Think\Loader::model($name,$layer);
}
/**
- * A函数用于实例化控制器 格式:[分组/]模块
+ * 实例化控制器 格式:[分组/]模块
* @param string $name 资源地址
* @param string $layer 控制层名称
- * @return Action|false
+ * @return object
*/
function A($name,$layer='') {
return Think\Loader::controll($name,$layer);
}
/**
- * 远程调用模块的操作方法 参数格式 [模块/控制器/]操作
+ * 调用模块的操作方法 参数格式 [模块/控制器/]操作
* @param string $url 调用地址
* @param string|array $vars 调用参数 支持字符串和数组
* @param string $layer 要调用的控制层名称
@@ -145,21 +109,6 @@ function R($url,$vars=array(),$layer='') {
return Think\Loader::action($url,$vars,$layer);
}
-/**
- * 字符串命名风格转换
- * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
- * @param string $name 字符串
- * @param integer $type 转换类型
- * @return string
- */
-function parse_name($name, $type=0) {
- if ($type) {
- return ucfirst(preg_replace("/_([a-zA-Z])/e", "strtoupper('\\1')", $name));
- } else {
- return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_"));
- }
-}
-
/**
* 导入所需的类库 同java的Import 本函数有缓存功能
* @param string $class 类库命名空间字符串
@@ -172,17 +121,13 @@ function import($class, $baseUrl = '', $ext= EXT ) {
}
/**
- * 自定义异常处理
+ * 抛出异常处理
* @param string $msg 异常消息
- * @param string $type 异常类型 默认为ThinkException
* @param integer $code 异常代码 默认为0
* @return void
*/
-function throw_exception($msg, $type='Think\Exception', $code=0) {
- if (class_exists($type))
- throw new $type($msg, $code, true);
- else
- Think\Error::halt($msg); // 异常类型不存在则输出错误信息字串
+function E($msg, $code=0) {
+ throw new Think\Exception($msg, $code);
}
/**
@@ -205,17 +150,17 @@ function dump($var, $echo=true, $label=null) {
* @return void
*/
function _404($msg='',$url='') {
- Think\Config::get('app_debug') && throw_exception($msg);
+ Think\Config::get('app_debug') && E($msg);
if($msg) Think\Log::record($msg,'ERR');
$url = $url?$url:Think\Config::get('url_404_redirect');
if($url) {
- redirect($url);
+ header('Location: ' . $url);
}else{
header('HTTP/1.1 404 Not Found');
// 确保FastCGI模式下正常
header('Status:404 Not Found');
- exit;
}
+ exit;
}
/**
@@ -228,35 +173,6 @@ function W($name, $data=array()) {
echo R($name,$data,'Widget');
}
-/**
- * URL重定向
- * @param string $url 重定向的URL地址
- * @param integer $time 重定向的等待时间(秒)
- * @param string $msg 重定向前的提示信息
- * @return void
- */
-function redirect($url, $time=0, $msg='') {
- //多行URL地址支持
- $url = str_replace(array("\n", "\r"), '', $url);
- if (empty($msg))
- $msg = "系统将在{$time}秒之后自动跳转到{$url}!";
- if (!headers_sent()) {
- // redirect
- if (0 === $time) {
- header('Location: ' . $url);
- } else {
- header("refresh:{$time};url={$url}");
- echo($msg);
- }
- exit();
- } else {
- $str = "";
- if ($time != 0)
- $str .= $msg;
- exit($str);
- }
-}
-
/**
* 缓存管理
* @param mixed $name 缓存名称,如果为数组表示进行缓存设置
@@ -266,21 +182,39 @@ function redirect($url, $time=0, $msg='') {
*/
function S($name,$value='',$options=null) {
static $cache = null;
- if(is_array($options)){
- // 缓存操作的同时初始化
- Think\Cache::connect($options);
+ if(is_array($options)){// 缓存操作的同时初始化
+ $cache = Think\Cache::connect($options);
}elseif(is_array($name)) { // 缓存初始化
- Think\Cache::connect($name);
- }elseif(is_null($cache)) { // 自动初始化
- Think\Cache::connect();
- $cache = true;
+ $cache = Think\Cache::connect($name);
+ return $cache;
+ }elseif(is_null($cache)) {// 自动初始化
+ $cache = Think\Cache::connect();
}
if(''=== $value){ // 获取缓存
- return Think\Cache::get($name);
+ return $cache->get($name);
}elseif(is_null($value)) { // 删除缓存
- return Think\Cache::rm($name);
+ return $cache->rm($name);
}else { // 缓存数据
- $expire = is_numeric($options)?$options:NULL;
- return Think\Cache::set($name, $value, $expire);
+ if(is_array($options)) {
+ $expire = is_numeric($options['expire'])?$options['expire']:NULL; //修复查询缓存无法设置过期时间
+ }else{
+ $expire = is_numeric($options)?$options:NULL; //默认快捷缓存设置过期时间
+ }
+ return $cache->set($name, $value, $expire);
+ }
+}
+
+/**
+ * 字符串命名风格转换
+ * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
+ * @param string $name 字符串
+ * @param integer $type 转换类型
+ * @return string
+ */
+function parse_name($name, $type=0) {
+ if ($type) {
+ return ucfirst(preg_replace("/_([a-zA-Z])/e", "strtoupper('\\1')", $name));
+ } else {
+ return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_"));
}
}
\ No newline at end of file