• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
xwlong
博客园    首页    新随笔    联系   管理    订阅  订阅
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'));//空方法处理
    }

 

posted on 2017-11-16 16:26  xwlong  阅读(2549)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3