thinkphpµÄerrorÔõô¹Ø±Õ
ÔÚʹÓÃthinkphp¿ò¼Ü¾ÙÐпª·¢Ê±£¬ÎÒÃǾ³£»áÓöµ½³ÌÐò±¨´íµÄÇéÐΡ£¶øµ±³ÌÐò±¨´íʱ£¬»áµ¯³öÒ»¸ö¹ýʧÌáÐÑ´°¿Ú£¬ÈôÊÇÎÒÃDz»´¦Öóͷ££¬Õâ¸ö´°¿Ú½«Ò»Ö±±£´æ£¬Ö±µ½ÊÖ¶¯¹Ø±Õ¡£ÕâÎÞÒÉ»áÓ°ÏìÓû§ÌåÑ飬²¢ÇÒÉÁ¿ª·¢ÕßÊ®·Öδ±ã¡£ÄÇôÔõÑùÔÚthinkphp¿ò¼ÜÖйرÕÕâ¸ö¹ýʧÌáÐÑ´°¿ÚÄØ£¿
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÖªµÀThinkPHP¿ò¼ÜµÄ¹ýʧÌáÐÑÒ³ÃæÊÇÓÉThinkPHP\Library\Think\ErrorÀàÖеÄdisplayÒªÁìÊä³öµÄ¡£ÒÔÊÇÖ»ÒªÔÚÕâ¸öÒªÁìÖÐÉÔ×÷Ð޸ģ¬¾Í¿ÉÒÔʵÏֹرչýʧÌáÐÑ´°¿ÚµÄ¹¦Ð§¡£
ÏêϸʵÏÖ°ì·¨ÈçÏ£º
ÕÒµ½ThinkPHP\Library\Think\ErrorÀàÎļþ£¬·¿ªÖ®ºóÕÒµ½displayÒªÁì¡£
ÔÚdisplayÒªÁìÖÐÕÒµ½ÒÔÏ´úÂ룺
if (isset($config['show_page_trace']) && $config['show_page_trace']) { // ... } else { // ÏÔʾ¹ýʧÐÅÏ¢ include $this->getErrorTemplate($exception); }
µÇ¼ºó¸´ÖÆ
¸Ã´úÂë¿éÓÃÓÚÅжÏÊÇ·ñÏÔʾÏêϸµÄ¹ýʧ¸ú×ÙÐÅÏ¢¡£ÎÒÃÇÐèÒª½«ÆäÖÐµÄ include $this->getErrorTemplate($exception) Ìæ»»³ÉÏÂÃæµÄ´úÂ룺
if (IS_AJAX) { //ÈôÊÇÊÇ Ajax ÇëÇó£¬Ö±½Ó·µ»Ø JSON ÃûÌõÄÊý¾Ý $result = array( 'code' => -1, 'msg' => $exception->getMessage() ); exit(json_encode($result)); } else { //ÈôÊÇÊÇͨË×ÇëÇó£¬ÔòÖ±½ÓÊäÍÉ»¯ÎóÐÅÏ¢ exit($exception->getMessage()); }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬IS_AJAXÊÇThinkPHP¿ò¼ÜÖеÄÒ»¸ö³£Á¿£¬ÓÃÓÚÅжÏÄ¿½ñÇëÇóÊÇ·ñÊÇAjaxÇëÇó¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÉúÑÄÐ޸ĺóµÄErrorÀàÎļþ£¬ÖØÐÂÔËÐгÌÐò¼´¿É¡£
ÏÖÔÚ£¬µ±³ÌÐò±¨´íʱ£¬½«²»ÔÙµ¯ÍÉ»¯ÎóÌáÐÑ´°¿Ú£¬¶øÊÇÖ±½Ó½«¹ýʧÐÅÏ¢Êä³öµ½Ò³ÃæÉÏ£¨ÈôÊÇÊÇAjaxÇëÇó£¬ÔòÒÔJSONÃûÌ÷µ»Ø£©¡£
ÐèҪעÖصÄÊÇ£¬¹Ø±Õ¹ýʧÌáÐÑ´°¿Ú»á¸øÓû§´øÀ´¸üºÃµÄÌåÑ飬µ«Í¬Ê±Ò²»áÔöÌí¿ª·¢Õߵĵ÷ÊÔÄѶȡ£Òò´Ë£¬ÔÚÕýʽÇéÐÎÏ£¬ÎÒÃÇÓ¦¸Ã½«¹ýʧÌáÐÑ´°¿Ú·¿ª£¬ÒÔ±ãʵʱ·¢Ã÷ºÍÐÞ¸´¹ýʧ¡£
×ܽ᣺
ThinkPHP¿ò¼ÜÖеĹýʧÌáÐÑ´°¿Ú¿ÉÒÔͨ¹ýÐÞ¸ÄErrorÀàµÄdisplayÒªÁìÀ´¹Ø±Õ¡£µ«ÔÚÕýʽÇéÐÎÏ£¬Ó¦¸Ã½«¹ýʧÌáÐÑ´°¿Ú·¿ªÒÔ±ãʵʱ·¢Ã÷ºÍÐÞ¸´¹ýʧ¡£¿ª·¢ÕßÔÚʹÓÃʱ£¬ÐèҪƾ֤ÏÖÕæÏàÐÎÎÞа´¦Öóͷ£¡£
ÒÔÉϾÍÊÇthinkphpµÄerrorÔõô¹Ø±ÕµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡