thinkphpÔõÑùÏÔʾ¹ýʧ
thinkphpÊÇÒ»ÖÖÊ¢ÐеÄwebÓ¦Óÿª·¢¿ò¼Ü£¬ËüÌṩÓÚ¿ìËÙ¡¢¸ßЧµÄ¿ª·¢Ä£Ê½¡£¿ÉÊÇÔÚ¿ª·¢µÄÀú³ÌÖУ¬¹ýʧ²»¿É×èÖ¹¡£±¾ÎĽ«ÏòÄúÏÈÈÝÔõÑùÔÚthinkphpÖÐÏÔʾ¹ýʧ¡£
¿ªÆôDebugģʽ
ÏÔʾ¹ýʧ×î¼òÆÓµÄÒªÁìÊÇ¿ªÆôThinkPHPµÄDebugģʽ¡£ÔÚThinkPHPµÄÈë¿ÚÎļþindex.phpÖУ¬¿ÉÒÔÕÒµ½ÒÔÏ´úÂ룺
define('APP_DEBUG', false);
µÇ¼ºó¸´ÖÆ
½«false¸ÄΪtrue£¬ÈçÏÂËùʾ£º
define('APP_DEBUG', true);
µÇ¼ºó¸´ÖÆ
¿ªÆôDebugģʽºó£¬ThinkPHP½«»áÏÔʾÏêϸµÄ¹ýʧÐÅÏ¢£¬°üÀ¨¹ýʧÀàÐÍ¡¢Îļþ·¾¶¡¢ÐкÅÒÔ¼°¹ýʧÐÅÏ¢¡£ÕâЩÐÅÏ¢¹ØÓÚ¿ª·¢ºÍµ÷ÊÔºÜÊÇÓÐÓá£
ÐÞ¸ÄÉèÖÃÎļþ
ÈôÊÇÄú²»Ï뿪ÆôDebugģʽ£¬»òÕßDebugģʽ²»¿ÉÖª×ãÄúµÄÐèÇó£¬Äú¿ÉÒÔͨ¹ýÐÞ¸ÄÉèÖÃÎļþÀ´ÏÔʾ¹ýʧÐÅÏ¢¡£ÔÚThinkPHPµÄÉèÖÃÎļþÖУ¬¿ÉÒÔÕÒµ½ÒÔÏ´úÂ룺
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
return [ 'app_debug' => false, ];
µÇ¼ºó¸´ÖÆ
½«false¸ÄΪtrue£¬ÈçÏÂËùʾ£º
return [ 'app_debug' => true, ];
µÇ¼ºó¸´ÖÆ
ÐÞ¸ÄÉèÖÃÎļþºó£¬¹ýʧÐÅÏ¢½«»á±»¼Í¼µ½ÈÕÖ¾ÎļþÖС£Äú¿ÉÒÔÔÚÈÕÖ¾ÎļþÖÐÉó²é¹ýʧÐÅÏ¢£¬ÈÕÖ¾ÎļþµÄ·¾¶Í¨³£ÊÇÔÚÏîÄ¿µÄruntimeĿ¼ÏµÄlogĿ¼ÖС£
×¢²á¹ýʧ»Øµ÷
³ýÁË¿ªÆôDebugģʽºÍÐÞ¸ÄÉèÖÃÎļþÒÔÍ⣬Äú»¹¿ÉÒÔʹÓÃThinkPHPµÄ×¢²á¹ýʧ»Øµ÷º¯ÊýÀ´²¶»ñºÍÏÔʾ¹ýʧÐÅÏ¢¡£ÔÚThinkPHPÖУ¬¿ÉÒÔͨ¹ýÔÚÓ¦Óòã×¢²á¹ýʧ»Øµ÷º¯ÊýÀ´²¶»ñºÍÏÔʾÒì³£¹ýʧ¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º
<?php namespace app\index\controller; use think\Controller; use think\exception\HttpException; class Error extends Controller { public function index(\Exception $e) { if($e instanceof HttpException) { return $this->renderHttpException($e); } else { return $this->renderException($e); } } protected function renderHttpException(HttpException $e) { return $e->getMessage(); } protected function renderException(\Exception $e) { return $e->getMessage(); } }
µÇ¼ºó¸´ÖÆ
ÔÚ¸ÃÀýÖУ¬ÎÒÃǽ¨ÉèÁËÒ»¸öÃûΪErrorµÄ¿ØÖÆÆ÷£¬²¢½ç˵ÁËindex()ÒªÁ죬ÓÃÓÚ´¦ÀíÒì³£¹ýʧ¡£ÔÚindex()ÒªÁìÖУ¬ÎÒÃǼì²éExceptionÊÇ·ñÊÇHttpExceptionÒì³£¡£ÈôÊÇÊÇ£¬ÎÒÃÇʹÓÃrenderHttpException()ÒªÁìÀ´ÏÔʾ¹ýʧÐÅÏ¢£»²»È»£¬ÎÒÃÇʹÓÃrenderException()ÒªÁìÀ´ÏÔʾ¹ýʧÐÅÏ¢¡£
Ҫע²áÕâ¸ö¹ýʧ»Øµ÷£¬¿ÉÒÔÔÚÏîÄ¿µÄapp.phpÉèÖÃÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺
'exception_handle' => '\\app\\index\\controller\\Error',
µÇ¼ºó¸´ÖÆ
ͨ¹ýÒÔÉϼ¸ÖÖ·½·¨£¬ÎÒÃÇ¿ÉÒÔÔÚ¿ª·¢ThinkPHPÓ¦ÓÃʱ²¶»ñºÍÏÔʾ¹ýʧÐÅÏ¢¡£Çмǣ¬ÔÚÐû²¼Ó¦ÓÃʱÎñ±Ø¹Ø±ÕDebugģʽ£¬ÒÔ×èÖ¹ÏòÓû§ÏÔʾ¹ý¶àµÄϸ½ÚÐÅÏ¢¡£
ÒÔÉϾÍÊÇthinkphpÔõÑùÏÔʾ¹ýʧµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡