thinkphp5.0 空模块、空控制器、空方法

空模块

'exception_handle'       => function(Exception $e){
        // 参数验证错误
        if ($e instanceof \think\exception\ValidateException) {
            return json($e->getError(), 422);
        }

        // 请求异常
        if ($e instanceof \think\exception\HttpException && request()->isAjax()) {
            return response($e->getMessage(), $e->getStatusCode());
        }
        return redirect(url('home/index/index'));//重定向至自定义错误提示页面
    },

或者

'exception_handle'       => '\\app\\common\\exception\\Http',
<?php
namespace app\common\exception;
use Exception;
use think\exception\Handle;
use think\exception\HttpException;
class Http extends Handle
{

    public function render(Exception $e)
    {
        // 参数验证错误
        if ($e instanceof ValidateException) {
            return json($e->getError(), 422);
        }

        // 请求异常
        if ($e instanceof HttpException && request()->isAjax()) {
            return response($e->getMessage(), $e->getStatusCode());
        }
        
        //TODO::开发者对异常的操作
        //可以在此交由系统处理
        return redirect(url('home/index/index'));//重定向至自定义错误提示页面
        //return parent::render($e);
    }

}

?>

空控制器

// 默认的空控制器名
    'empty_controller'       => 'Error',
<?php
namespace app\home\controller;
use think\Controller;
use think\Request;

class Error extends Controller
{
    public function index(Request $request)
    {
        $this->redirect(url('home/index/index'));//空控制器处理        
    }
}

空方法

public function _empty(){
        $this->redirect(url('home/index/index'));//空方法处理
    }

 

转载于:https://www.cnblogs.com/xwlong/p/7844995.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值