Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThinkPHP6多应用模式 #8

Open
sPcHyGvKwBnM opened this issue Dec 3, 2020 · 7 comments
Open

ThinkPHP6多应用模式 #8

sPcHyGvKwBnM opened this issue Dec 3, 2020 · 7 comments

Comments

@sPcHyGvKwBnM
Copy link

请问,在ExceptionHandle自定义异常之后,app_debug和enable是打开状态,return parent::render($request,$e); 是原生的异常页面,单应用模式下是正常的,应该如何在多应用模式下自行调整继续使用呢,我看不太懂源码是怎样运转的

@edenleung
Copy link
Collaborator

我试试

@edenleung
Copy link
Collaborator

edenleung commented Dec 3, 2020

我在多应用下 抛出一个异常 没发现问题。

访问路径 /member 测试

要不你试试这个 demo
https://github.com/edenleung/demo

@sPcHyGvKwBnM
Copy link
Author

Demo没问题,我再补充一下,我的多应用是把provider.php和ExceptionHandle.php复制进我的多应用目录里,然后我把provider.php里的handle=>我在多应用目录那个新的 , 还是说这种方式是不对的,我应该多应用下像demo一样只用一套handle,然后用if分别处理来自api和网页的异常呢

@edenleung
Copy link
Collaborator

edenleung commented Dec 3, 2020

估计是被当前应用下 provider.phpthink\exception\Handle 覆盖了

暂时可以换成这样

方式1

xxx/provider.php

<?php
use think\Whoops\RenderExceptionWithWhoops;
use app\Request;

// 容器Provider定义文件
return [
    'think\Request'          => Request::class,
    'think\exception\Handle' => RenderExceptionWithWhoops::class,
];

方式2

去除应用下的 think\exception\Handle

@edenleung
Copy link
Collaborator

看你上面说的(要区分api 与 网页)的异常, 是不是有后续操作(类似写日志)

@edenleung edenleung reopened this Dec 3, 2020
@sPcHyGvKwBnM
Copy link
Author

稍等我也传个demo

@sPcHyGvKwBnM
Copy link
Author

Demo https://gitee.com/fafen/test.git
须安装compose依赖 thinkphp多应用 composer require topthink/think-multi-app
think-whoops composer require xiaodi/think-whoops
路由地址 index.php/api/banner
参数 /id/1 一片空白,无返回 实例 index.php/api/banner/id/1
/id/0.1 数值非整型 json格式错误

由于我在多应用下的ExceptionHandle调整 json结构的异常会输出只有json结构的页面,但是app_debug打开时,会交给系统处理,现在的问题是whoops识别不到了,出现的是原生异常页面,代码在app\api\ExceptionHandle
在banner类getbanner方法下throw new Exception会返回原生异常页面,注释掉可以走验证器返回json错误

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants