PHP code example of chomyeong / errorcode
1. Go to this page and download the library: Download chomyeong/errorcode library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chomyeong / errorcode example snippets
$ret = [
'code'=>100,
'msg'=>'用户名错误',
'data'=>[],
];
echo json_encode($ret);
$ret = [
'code'=>101,
'msg'=>'密码错误',
'data'=>[],
];
echo json_encode($ret);
$ret = [
'code'=>1011,
'msg'=>'参数错误',
'data'=>[],
];
echo json_encode($ret);
return [
['errDefine' => 'ERROR_SHOP_NAME', 'index' => 1000, 'errMsg' => '商城名称错误'],
['errDefine' => 'ERROR_SHOP_NAME1','errMsg' => '商城名称错误1'],
['errDefine' => 'ERROR_ORDER_ERROR', 'index' => 2000, 'errMsg' => '商城登录错误'],
];
return [
['errDefine' => 'ERROR_SHOP_NAME', 'index' => 1000, 'errMsg' => '商城名称错误'],
['errDefine' => 'ERROR_SHOP_LOGIN', 'index' => 2000, 'errMsg' => '商城登录错误'],
];
use chomyeong\errorcode\Error;
$err = new Error();
$err->responseError(ERROR_PARAM);
// 要返回的数据
$data = [
'info' => [
'id' => 1,
'username' => 'chomyeong',
],
];
$err->responseSuccess($data);
$options = [
'dataBody'=>'info',
'errBody'=>'code',
'isErrorBody'=>'error',
'errMsgBody'=>'message',
];
$err = new Error($options);
$options = [
'errBody'=>'code',
];
$err = new Error($options);