×ðÁú¿­Ê±

thinkphp5.0ÔõÑùÉèÖùýʧҳ

I. ThinkPHP 5.0 ¹ýʧҳµÄ×÷ÓÃ

¹ýʧҳÃæÖ÷ÒªÓÃÓÚ²¶»ñÓ¦ÓóÌÐòÔÚÔËÐÐʱ·ºÆðµÄ¹ýʧ²¢Ìṩ»á¼û¹ýʧÈÕÖ¾µÄÒªÁì¡£

¹ýʧҳÃ滹֧³Öʵʱ¼Í¼¹ýʧÐÅÏ¢£¬¿ÉÒÔ¿ìËÙÅŲéÏ¢Õù¾öÉú²úÇéÐÎÖеĹýʧ¡£

II. ÉèÖùýʧҳ

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

ÉèÖùýʧҳÃæÐèÒªÔÚÓ¦ÓóÌÐòµÄÉèÖÃÎļþÖоÙÐУ¬ÀýÈçÔÚ config.php ÎļþÖÐÔöÌíÒÔÏÂÉèÖãº

'exception_handle'        => 'app\index\exception\Http',

µÇ¼ºó¸´ÖÆ

ÆäÖÐ app\index\exception\Http ÊÇÖ¸Òì³£´¦Öóͷ£ÀàËùÔÚµÄÃüÃû¿Õ¼äºÍÀàÃû¡£Òì³£´¦Öóͷ£ÀàÐèÒª¼ÌÐø think\exception\Handle À࣬²¢ÖØд render ÒªÁìʵÏÖ×Ô½ç˵Òì³£ÐÅÏ¢µÄÊä³ö¡£

III. ¹ýʧҳµÄĬÈÏÉèÖÃ

ThinkPHP 5.0 ÖеÄĬÈϹýʧҳ°üÀ¨ÒÔÏÂÄÚÈÝ£º

Òì³£ÀàÃû

Òì³£¹ýʧÂë

Òì³£¹ýʧÐÎò

Òì³£¹ýʧÎļþ¼°ÐкÅ

Òì³£×·ËÝÐÅÏ¢

ÒÔÉÏÐÅÏ¢¿É×ÊÖú¿ìËÙ¶¨Î»¹ýʧλÖò¢¾ÙÐиú×ÙÆÊÎö¡£³ý´ËÖ®Í⣬¹ýʧҳ»¹ÌṩÁ˲Ù×÷°´Å¥£¬ÒԱ㿪·¢Õß¾ÙÐÐһЩ³£ÓòÙ×÷¡£

IV. ×Ô½ç˵¹ýʧҳ

¹ýʧҳ»¹Ö§³Ö×Ô½ç˵£¬Ö»ÐèÔÚ¿ØÖÆÆ÷ÖмÌÐø think\exception\Handle À࣬²¢ÖØд render ÒªÁì¼´¿É£¬ÀýÈ磺

namespace app\index\exception;

use think\exception\Handle;

class Http extends Handle
{
    public function render(\Exception $e)
    {
        if ($e instanceof HttpException) {
            $status = $e->getStatusCode();
        } else {
            $status = 404;
        }
        $data = [
            'status' => $status,
            'message' => $this->getMessage($e),
            'exception' => $this->isDebug() ? $this->getTrace($e) : [],
        ];
        return json($data);
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëչʾÁËÔõÑù×Ô½ç˵Òì³£ÐÅÏ¢£¬ÔÚ±¬·¢¹ýʧʱ·µ»Ø JSON ¹¤Ç©×ÖÌõĹýʧÐÅÏ¢¡£

ÒÔÉϾÍÊÇthinkphp5.0ÔõÑùÉèÖùýʧҳµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿