mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 19:42:47 +08:00
优化error和success方法
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app;
|
||||
|
||||
@@ -64,7 +64,8 @@ abstract class BaseController
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
@@ -103,68 +104,70 @@ abstract class BaseController
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
public function success($msg = '操作成功',$jump_to_url = null,$code = 200,$params = [])
|
||||
public function success($msg = '操作成功', $jump_to_url = null, $code = 200, $params = [])
|
||||
{
|
||||
|
||||
if(is_null($jump_to_url)){
|
||||
if (is_null($jump_to_url)) {
|
||||
$jump_to_url = \request()->server('HTTP_REFERER');
|
||||
}else{
|
||||
if($jump_to_url instanceof Url){
|
||||
} else {
|
||||
if ($jump_to_url instanceof Url) {
|
||||
|
||||
$jump_to_url = $jump_to_url;
|
||||
}else{
|
||||
$jump_to_url = (string)$jump_to_url;
|
||||
} else {
|
||||
if (strpos($jump_to_url, 'http') !== 0) {
|
||||
$jump_to_url = url($jump_to_url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'msg'=>$msg,
|
||||
'jump_to_url'=>$jump_to_url,
|
||||
'params'=>$params
|
||||
'msg' => $msg,
|
||||
'jump_to_url' => $jump_to_url,
|
||||
'params' => $params
|
||||
];
|
||||
|
||||
if(\request()->isAjax()){
|
||||
$data['jump_to_url'] = (string)$jump_to_url;
|
||||
if($code == 200){
|
||||
if (\request()->isAjax()) {
|
||||
$data['jump_to_url'] = $jump_to_url;
|
||||
if ($code == 200) {
|
||||
$code = 0;
|
||||
}
|
||||
throw new HttpResponseException(json_message($data,$code,$msg));
|
||||
throw new HttpResponseException(json_message($data, $code, $msg));
|
||||
}
|
||||
|
||||
View::assign($data);
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/success'),$code));
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/success'), $code));
|
||||
}
|
||||
public function error($msg = '操作失败',$jump_to_url = null,$code = 200,$params = [])
|
||||
public function error($msg = '操作失败', $jump_to_url = null, $code = 200, $params = [])
|
||||
{
|
||||
|
||||
if(is_null($jump_to_url)){
|
||||
if (is_null($jump_to_url)) {
|
||||
$jump_to_url = \request()->server('HTTP_REFERER');
|
||||
}else{
|
||||
if($jump_to_url instanceof Url){
|
||||
} else {
|
||||
if ($jump_to_url instanceof Url) {
|
||||
|
||||
$jump_to_url = $jump_to_url;
|
||||
}else{
|
||||
$jump_to_url = (string)$jump_to_url;
|
||||
} else {
|
||||
if (strpos($jump_to_url, 'http') !== 0) {
|
||||
$jump_to_url = url($jump_to_url);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'msg'=>$msg,
|
||||
'jump_to_url'=>$jump_to_url,
|
||||
'params'=>$params
|
||||
'msg' => $msg,
|
||||
'jump_to_url' => $jump_to_url,
|
||||
'params' => $params
|
||||
];
|
||||
|
||||
if(\request()->isAjax()){
|
||||
$data['jump_to_url'] = (string)$jump_to_url;
|
||||
if($code == 200){
|
||||
if (\request()->isAjax()) {
|
||||
$data['jump_to_url'] = $jump_to_url;
|
||||
if ($code == 200) {
|
||||
$code = 500;
|
||||
}
|
||||
throw new HttpResponseException(json_message($data,$code,$msg));
|
||||
throw new HttpResponseException(json_message($data, $code, $msg));
|
||||
}
|
||||
|
||||
View::assign($data);
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/error'),$code));
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/error'), $code));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user