search
HomePHP FrameworkThinkPHPAnalysis thinkphp5 shows render incompatibility problem

Analysis thinkphp5 shows render incompatibility problem

Nov 29, 2021 pm 03:19 PM
php frameworkthinkphp5.1

The following thinkphp framework tutorial column will introduce to you the render incompatibility issue of TP5 custom global exception handling prompts. I hope it will be helpful to friends in need!

TP5 custom global exception handling, all exceptions thrown are passed automatically Define the render method to render and then return to the client for display.
You need to customize the render method of the handle and overwrite it:

namespace app\lib\exception;  
  
use think\Exception;  
use think\exception\Handle;
class ExceptionHandler extends Handle  
{  
  public function render(Exception $e)  
    {  
        //TODO:
        return json('invalid request')
    }  
}

After that, the postman verification interface appears and the following error message is incompatible:
Analysis thinkphp5 shows render incompatibility problem

Trace the original Handle. php file,
Analysis thinkphp5 shows render incompatibility problem

Check use and find that the source file uses Exception, and I use think\Exception:
Analysis thinkphp5 shows render incompatibility problem

Modify the code:

namespace app\lib\exception;  
  
use Exception;  
use think\exception\Handle;
class ExceptionHandler extends Handle  
{  
  public function render(Exception $e)  
    { 
        //TODO:
        return json('invalid request')
    }  
}

The result is correct:
Analysis thinkphp5 shows render incompatibility problem

The above is the detailed content of Analysis thinkphp5 shows render incompatibility problem. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools