首页 技术 正文
技术 2022年11月15日
0 收藏 354 点赞 2,529 浏览 1158 个字

myphp.vip

1.异常处理:

【代码越抽象,复用性越高】

【封装性越好,适应代码变化的能力越强】

慕课网 微信小程序商城构建全栈应用  tp5【总结】

【】

<?php
/**
* Created by PhpStorm.
* User: 14155
* Date: 2018/12/22
* Time: 23:40
*/namespace app\lib\exception;use think\Exception;
use think\exception\Handle;
use think\Request;class ExceptionHandler extends Handle
{
private $code;
private $msg;
private $errorCode; //需要返回客户端当前的Url
public function render(\Exception $e)
{
if ($e instanceof BaseException) {
// 如果是自定义的消息
$this->code = $e->code;
$this->msg = $e->msg;
$this->errorCode = $e->errorCode;
} else {
$this->code = 500;
$this->msg = '服务器内部错误';
$this->errorCode = 999;
}
$request = Request::instance();
$result = [
'msg' => $this->msg,
'error_code' => $this->errorCode,
'request_url' => $request->url()
];
return json($result, $this->code);
}
}

【】

<?php
/**
* Created by PhpStorm.
* User: 14155
* Date: 2018/11/10
* Time: 0:31
*/namespace app\lib\exception;use think\Exception;class BaseException extends Exception
{
// HTTP 状态码 404,200
public $code = 400; // 错误具体信息(英文)
public $msg = 'Parameter error'; // 自定义的错误码
public $errorCode = 10000;}

【】

<?php
/**
* Created by PhpStorm.
* User: 14155
* Date: 2018/12/22
* Time: 23:44
*/namespace app\lib\exception;class BannerMissException extends BaseException
{
public $code = 404;
//请求的banner不存在;
public $msg = 'The request Banner does not exist';
public $errorCode = 40000;
}

【】

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,990
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,132
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,843