mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
Merge pull request #176 from chenjxlg/master
助手函数 是否定义判断,方便用户重写helper函数
This commit is contained in:
374
helper.php
374
helper.php
@@ -33,9 +33,11 @@ use think\View;
|
|||||||
* @param string $ext 类库后缀
|
* @param string $ext 类库后缀
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function load_trait($class, $ext = EXT)
|
if (!function_exists('load_trait')) {
|
||||||
{
|
function load_trait($class, $ext = EXT)
|
||||||
return Loader::import($class, TRAIT_PATH, $ext);
|
{
|
||||||
|
return Loader::import($class, TRAIT_PATH, $ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,10 +49,12 @@ function load_trait($class, $ext = EXT)
|
|||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function exception($msg, $code = 0, $exception = '')
|
if (!function_exists('exception')) {
|
||||||
{
|
function exception($msg, $code = 0, $exception = '')
|
||||||
$e = $exception ?: '\think\Exception';
|
{
|
||||||
throw new $e($msg, $code);
|
$e = $exception ?: '\think\Exception';
|
||||||
|
throw new $e($msg, $code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,12 +64,14 @@ function exception($msg, $code = 0, $exception = '')
|
|||||||
* @param integer|string $dec 小数位 如果是m 表示统计内存占用
|
* @param integer|string $dec 小数位 如果是m 表示统计内存占用
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function debug($start, $end = '', $dec = 6)
|
if (!function_exists('debug')) {
|
||||||
{
|
function debug($start, $end = '', $dec = 6)
|
||||||
if ('' == $end) {
|
{
|
||||||
Debug::remark($start);
|
if ('' == $end) {
|
||||||
} else {
|
Debug::remark($start);
|
||||||
return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec);
|
} else {
|
||||||
|
return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +82,11 @@ function debug($start, $end = '', $dec = 6)
|
|||||||
* @param string $lang 语言
|
* @param string $lang 语言
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function lang($name, $vars = [], $lang = '')
|
if (!function_exists('lang')) {
|
||||||
{
|
function lang($name, $vars = [], $lang = '')
|
||||||
return Lang::get($name, $vars, $lang);
|
{
|
||||||
|
return Lang::get($name, $vars, $lang);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,12 +96,14 @@ function lang($name, $vars = [], $lang = '')
|
|||||||
* @param string $range 作用域
|
* @param string $range 作用域
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function config($name = '', $value = null, $range = '')
|
if (!function_exists('config')) {
|
||||||
{
|
function config($name = '', $value = null, $range = '')
|
||||||
if (is_null($value) && is_string($name)) {
|
{
|
||||||
return Config::get($name, $range);
|
if (is_null($value) && is_string($name)) {
|
||||||
} else {
|
return Config::get($name, $range);
|
||||||
return Config::set($name, $value, $range);
|
} else {
|
||||||
|
return Config::set($name, $value, $range);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,28 +114,30 @@ function config($name = '', $value = null, $range = '')
|
|||||||
* @param string $filter 过滤方法
|
* @param string $filter 过滤方法
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function input($key, $default = null, $filter = null)
|
if (!function_exists('input')) {
|
||||||
{
|
function input($key, $default = null, $filter = null)
|
||||||
if (0 === strpos($key, '?')) {
|
{
|
||||||
$key = substr($key, 1);
|
if (0 === strpos($key, '?')) {
|
||||||
$has = true;
|
$key = substr($key, 1);
|
||||||
}
|
$has = true;
|
||||||
if ($pos = strpos($key, '.')) {
|
}
|
||||||
// 指定参数来源
|
if ($pos = strpos($key, '.')) {
|
||||||
$method = substr($key, 0, $pos);
|
// 指定参数来源
|
||||||
if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
|
$method = substr($key, 0, $pos);
|
||||||
$key = substr($key, $pos + 1);
|
if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
|
||||||
|
$key = substr($key, $pos + 1);
|
||||||
|
} else {
|
||||||
|
$method = 'param';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// 默认为自动判断
|
||||||
$method = 'param';
|
$method = 'param';
|
||||||
}
|
}
|
||||||
} else {
|
if (isset($has)) {
|
||||||
// 默认为自动判断
|
return request()->has($key, $method, $default);
|
||||||
$method = 'param';
|
} else {
|
||||||
}
|
return request()->$method($key, $default, $filter);
|
||||||
if (isset($has)) {
|
}
|
||||||
return request()->has($key, $method, $default);
|
|
||||||
} else {
|
|
||||||
return request()->$method($key, $default, $filter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,9 +147,11 @@ function input($key, $default = null, $filter = null)
|
|||||||
* @param array $data 传人的参数
|
* @param array $data 传人的参数
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function widget($name, $data = [])
|
if (!function_exists('widget')) {
|
||||||
{
|
function widget($name, $data = [])
|
||||||
return Loader::action($name, $data, 'widget');
|
{
|
||||||
|
return Loader::action($name, $data, 'widget');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,9 +161,11 @@ function widget($name, $data = [])
|
|||||||
* @param bool $appendSuffix 是否添加类名后缀
|
* @param bool $appendSuffix 是否添加类名后缀
|
||||||
* @return \think\Model
|
* @return \think\Model
|
||||||
*/
|
*/
|
||||||
function model($name = '', $layer = 'model', $appendSuffix = false)
|
if (!function_exists('model')) {
|
||||||
{
|
function model($name = '', $layer = 'model', $appendSuffix = false)
|
||||||
return Loader::model($name, $layer, $appendSuffix);
|
{
|
||||||
|
return Loader::model($name, $layer, $appendSuffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,9 +175,11 @@ function model($name = '', $layer = 'model', $appendSuffix = false)
|
|||||||
* @param bool $appendSuffix 是否添加类名后缀
|
* @param bool $appendSuffix 是否添加类名后缀
|
||||||
* @return \think\Validate
|
* @return \think\Validate
|
||||||
*/
|
*/
|
||||||
function validate($name = '', $layer = 'validate', $appendSuffix = false)
|
if (!function_exists('validate')) {
|
||||||
{
|
function validate($name = '', $layer = 'validate', $appendSuffix = false)
|
||||||
return Loader::validate($name, $layer, $appendSuffix);
|
{
|
||||||
|
return Loader::validate($name, $layer, $appendSuffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,9 +188,11 @@ function validate($name = '', $layer = 'validate', $appendSuffix = false)
|
|||||||
* @param array|string $config 数据库配置参数
|
* @param array|string $config 数据库配置参数
|
||||||
* @return \think\db\Query
|
* @return \think\db\Query
|
||||||
*/
|
*/
|
||||||
function db($name = '', $config = [])
|
if (!function_exists('db')) {
|
||||||
{
|
function db($name = '', $config = [])
|
||||||
return Db::connect($config)->name($name);
|
{
|
||||||
|
return Db::connect($config)->name($name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,9 +202,11 @@ function db($name = '', $config = [])
|
|||||||
* @param bool $appendSuffix 是否添加类名后缀
|
* @param bool $appendSuffix 是否添加类名后缀
|
||||||
* @return \think\Controller
|
* @return \think\Controller
|
||||||
*/
|
*/
|
||||||
function controller($name, $layer = 'controller', $appendSuffix = false)
|
if (!function_exists('controller')) {
|
||||||
{
|
function controller($name, $layer = 'controller', $appendSuffix = false)
|
||||||
return Loader::controller($name, $layer, $appendSuffix);
|
{
|
||||||
|
return Loader::controller($name, $layer, $appendSuffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,9 +217,11 @@ function controller($name, $layer = 'controller', $appendSuffix = false)
|
|||||||
* @param bool $appendSuffix 是否添加类名后缀
|
* @param bool $appendSuffix 是否添加类名后缀
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
|
if (!function_exists('action')) {
|
||||||
{
|
function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
|
||||||
return Loader::action($url, $vars, $layer, $appendSuffix);
|
{
|
||||||
|
return Loader::action($url, $vars, $layer, $appendSuffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,9 +231,11 @@ function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
|
|||||||
* @param string $ext 导入的文件扩展名
|
* @param string $ext 导入的文件扩展名
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function import($class, $baseUrl = '', $ext = EXT)
|
if (!function_exists('import')) {
|
||||||
{
|
function import($class, $baseUrl = '', $ext = EXT)
|
||||||
return Loader::import($class, $baseUrl, $ext);
|
{
|
||||||
|
return Loader::import($class, $baseUrl, $ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,9 +244,11 @@ function import($class, $baseUrl = '', $ext = EXT)
|
|||||||
* @param string $ext 类库后缀
|
* @param string $ext 类库后缀
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function vendor($class, $ext = EXT)
|
if (!function_exists('vendor')) {
|
||||||
{
|
function vendor($class, $ext = EXT)
|
||||||
return Loader::import($class, VENDOR_PATH, $ext);
|
{
|
||||||
|
return Loader::import($class, VENDOR_PATH, $ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,9 +258,11 @@ function vendor($class, $ext = EXT)
|
|||||||
* @param string $label 标签 默认为空
|
* @param string $label 标签 默认为空
|
||||||
* @return void|string
|
* @return void|string
|
||||||
*/
|
*/
|
||||||
function dump($var, $echo = true, $label = null)
|
if (!function_exists('dump')) {
|
||||||
{
|
function dump($var, $echo = true, $label = null)
|
||||||
return Debug::dump($var, $echo, $label);
|
{
|
||||||
|
return Debug::dump($var, $echo, $label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,9 +273,11 @@ function dump($var, $echo = true, $label = null)
|
|||||||
* @param bool|string $domain 域名
|
* @param bool|string $domain 域名
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function url($url = '', $vars = '', $suffix = true, $domain = false)
|
if (!function_exists('url')) {
|
||||||
{
|
function url($url = '', $vars = '', $suffix = true, $domain = false)
|
||||||
return Url::build($url, $vars, $suffix, $domain);
|
{
|
||||||
|
return Url::build($url, $vars, $suffix, $domain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,23 +287,25 @@ function url($url = '', $vars = '', $suffix = true, $domain = false)
|
|||||||
* @param string $prefix 前缀
|
* @param string $prefix 前缀
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function session($name, $value = '', $prefix = null)
|
if (!function_exists('session')) {
|
||||||
{
|
function session($name, $value = '', $prefix = null)
|
||||||
if (is_array($name)) {
|
{
|
||||||
// 初始化
|
if (is_array($name)) {
|
||||||
Session::init($name);
|
// 初始化
|
||||||
} elseif (is_null($name)) {
|
Session::init($name);
|
||||||
// 清除
|
} elseif (is_null($name)) {
|
||||||
Session::clear($value);
|
// 清除
|
||||||
} elseif ('' === $value) {
|
Session::clear($value);
|
||||||
// 判断或获取
|
} elseif ('' === $value) {
|
||||||
return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix);
|
// 判断或获取
|
||||||
} elseif (is_null($value)) {
|
return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix);
|
||||||
// 删除
|
} elseif (is_null($value)) {
|
||||||
return Session::delete($name, $prefix);
|
// 删除
|
||||||
} else {
|
return Session::delete($name, $prefix);
|
||||||
// 设置
|
} else {
|
||||||
return Session::set($name, $value, $prefix);
|
// 设置
|
||||||
|
return Session::set($name, $value, $prefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,23 +316,25 @@ function session($name, $value = '', $prefix = null)
|
|||||||
* @param mixed $option 参数
|
* @param mixed $option 参数
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function cookie($name, $value = '', $option = null)
|
if (!function_exists('cookie')) {
|
||||||
{
|
function cookie($name, $value = '', $option = null)
|
||||||
if (is_array($name)) {
|
{
|
||||||
// 初始化
|
if (is_array($name)) {
|
||||||
Cookie::init($name);
|
// 初始化
|
||||||
} elseif (is_null($name)) {
|
Cookie::init($name);
|
||||||
// 清除
|
} elseif (is_null($name)) {
|
||||||
Cookie::clear($value);
|
// 清除
|
||||||
} elseif ('' === $value) {
|
Cookie::clear($value);
|
||||||
// 获取
|
} elseif ('' === $value) {
|
||||||
return Cookie::get($name);
|
// 获取
|
||||||
} elseif (is_null($value)) {
|
return Cookie::get($name);
|
||||||
// 删除
|
} elseif (is_null($value)) {
|
||||||
return Cookie::delete($name);
|
// 删除
|
||||||
} else {
|
return Cookie::delete($name);
|
||||||
// 设置
|
} else {
|
||||||
return Cookie::set($name, $value, $option);
|
// 设置
|
||||||
|
return Cookie::set($name, $value, $option);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,29 +345,31 @@ function cookie($name, $value = '', $option = null)
|
|||||||
* @param mixed $options 缓存参数
|
* @param mixed $options 缓存参数
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function cache($name, $value = '', $options = null)
|
if (!function_exists('cache')) {
|
||||||
{
|
function cache($name, $value = '', $options = null)
|
||||||
if (is_array($options)) {
|
{
|
||||||
// 缓存操作的同时初始化
|
|
||||||
Cache::connect($options);
|
|
||||||
} elseif (is_array($name)) {
|
|
||||||
// 缓存初始化
|
|
||||||
return Cache::connect($name);
|
|
||||||
}
|
|
||||||
if ('' === $value) {
|
|
||||||
// 获取缓存
|
|
||||||
return Cache::get($name);
|
|
||||||
} elseif (is_null($value)) {
|
|
||||||
// 删除缓存
|
|
||||||
return Cache::rm($name);
|
|
||||||
} else {
|
|
||||||
// 缓存数据
|
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
$expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间
|
// 缓存操作的同时初始化
|
||||||
} else {
|
Cache::connect($options);
|
||||||
$expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
|
} elseif (is_array($name)) {
|
||||||
|
// 缓存初始化
|
||||||
|
return Cache::connect($name);
|
||||||
|
}
|
||||||
|
if ('' === $value) {
|
||||||
|
// 获取缓存
|
||||||
|
return Cache::get($name);
|
||||||
|
} elseif (is_null($value)) {
|
||||||
|
// 删除缓存
|
||||||
|
return Cache::rm($name);
|
||||||
|
} else {
|
||||||
|
// 缓存数据
|
||||||
|
if (is_array($options)) {
|
||||||
|
$expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间
|
||||||
|
} else {
|
||||||
|
$expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
|
||||||
|
}
|
||||||
|
return Cache::set($name, $value, $expire);
|
||||||
}
|
}
|
||||||
return Cache::set($name, $value, $expire);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,12 +379,14 @@ function cache($name, $value = '', $options = null)
|
|||||||
* @param string $level 日志级别
|
* @param string $level 日志级别
|
||||||
* @return void|array
|
* @return void|array
|
||||||
*/
|
*/
|
||||||
function trace($log = '[think]', $level = 'log')
|
if (!function_exists('trace')) {
|
||||||
{
|
function trace($log = '[think]', $level = 'log')
|
||||||
if ('[think]' === $log) {
|
{
|
||||||
return Log::getLog();
|
if ('[think]' === $log) {
|
||||||
} else {
|
return Log::getLog();
|
||||||
Log::record($log, $level);
|
} else {
|
||||||
|
Log::record($log, $level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,9 +394,11 @@ function trace($log = '[think]', $level = 'log')
|
|||||||
* 获取当前Request对象实例
|
* 获取当前Request对象实例
|
||||||
* @return Request
|
* @return Request
|
||||||
*/
|
*/
|
||||||
function request()
|
if (!function_exists('request')) {
|
||||||
{
|
function request()
|
||||||
return Request::instance();
|
{
|
||||||
|
return Request::instance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -367,9 +409,11 @@ function request()
|
|||||||
* @param string $type
|
* @param string $type
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
function response($data = [], $code = 200, $header = [], $type = 'html')
|
if (!function_exists('response')) {
|
||||||
{
|
function response($data = [], $code = 200, $header = [], $type = 'html')
|
||||||
return Response::create($data, $type, $code, $header);
|
{
|
||||||
|
return Response::create($data, $type, $code, $header);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,9 +423,11 @@ function response($data = [], $code = 200, $header = [], $type = 'html')
|
|||||||
* @param integer $code 状态码
|
* @param integer $code 状态码
|
||||||
* @return \think\response\View
|
* @return \think\response\View
|
||||||
*/
|
*/
|
||||||
function view($template = '', $vars = [], $code = 200)
|
if (!function_exists('view')) {
|
||||||
{
|
function view($template = '', $vars = [], $code = 200)
|
||||||
return Response::create($template, 'view', $code)->vars($vars);
|
{
|
||||||
|
return Response::create($template, 'view', $code)->vars($vars);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -392,9 +438,11 @@ function view($template = '', $vars = [], $code = 200)
|
|||||||
* @param array $options 参数
|
* @param array $options 参数
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
function json($data = [], $code = 200, $header = [], $options = [])
|
if (!function_exists('json')) {
|
||||||
{
|
function json($data = [], $code = 200, $header = [], $options = [])
|
||||||
return Response::create($data, 'json', $code, $header, $options);
|
{
|
||||||
|
return Response::create($data, 'json', $code, $header, $options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -405,9 +453,11 @@ function json($data = [], $code = 200, $header = [], $options = [])
|
|||||||
* @param array $options 参数
|
* @param array $options 参数
|
||||||
* @return \think\response\Jsonp
|
* @return \think\response\Jsonp
|
||||||
*/
|
*/
|
||||||
function jsonp($data = [], $code = 200, $header = [], $options = [])
|
if (!function_exists('jsonp')) {
|
||||||
{
|
function jsonp($data = [], $code = 200, $header = [], $options = [])
|
||||||
return Response::create($data, 'jsonp', $code, $header, $options);
|
{
|
||||||
|
return Response::create($data, 'jsonp', $code, $header, $options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -418,9 +468,11 @@ function jsonp($data = [], $code = 200, $header = [], $options = [])
|
|||||||
* @param array $options 参数
|
* @param array $options 参数
|
||||||
* @return \think\response\Xml
|
* @return \think\response\Xml
|
||||||
*/
|
*/
|
||||||
function xml($data = [], $code = 200, $header = [], $options = [])
|
if (!function_exists('xml')) {
|
||||||
{
|
function xml($data = [], $code = 200, $header = [], $options = [])
|
||||||
return Response::create($data, 'xml', $code, $header, $options);
|
{
|
||||||
|
return Response::create($data, 'xml', $code, $header, $options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -430,13 +482,15 @@ function xml($data = [], $code = 200, $header = [], $options = [])
|
|||||||
* @param integer $code 状态码
|
* @param integer $code 状态码
|
||||||
* @return \think\response\Redirect
|
* @return \think\response\Redirect
|
||||||
*/
|
*/
|
||||||
function redirect($url = [], $params = [], $code = 302)
|
if (!function_exists('redirect')) {
|
||||||
{
|
function redirect($url = [], $params = [], $code = 302)
|
||||||
if (is_integer($params)) {
|
{
|
||||||
$code = $params;
|
if (is_integer($params)) {
|
||||||
$params = [];
|
$code = $params;
|
||||||
|
$params = [];
|
||||||
|
}
|
||||||
|
return Response::create($url, 'redirect', $code)->params($params);
|
||||||
}
|
}
|
||||||
return Response::create($url, 'redirect', $code)->params($params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -445,7 +499,9 @@ function redirect($url = [], $params = [], $code = 302)
|
|||||||
* @param string $message 错误信息
|
* @param string $message 错误信息
|
||||||
* @param array $header 参数
|
* @param array $header 参数
|
||||||
*/
|
*/
|
||||||
function abort($code, $message = null, $header = [])
|
if (!function_exists('abort')) {
|
||||||
{
|
function abort($code, $message = null, $header = [])
|
||||||
throw new \think\exception\HttpException($code, $message, null, $header);
|
{
|
||||||
|
throw new \think\exception\HttpException($code, $message, null, $header);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user