RSS订阅Good Luck To You!
你现在的位置:网站首页 / ThinkPHP / 正文内容

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

13590 ThinkPHP | 2020年01月17日

1.空模块定义

'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);
    }

}

?>


2.空控制器定义

'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'));//空控制器处理        
    }
}


3.空方法


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


上一篇:thinkphp5 select 返回数组的方法

下一篇:PHP防CC拦截代码

猜你喜欢