Use ThinkPHP3.2.3 to encounter a strange problem, formal environment escalation error, hint
"Page Error! Please try again later. "
In order to see what is wrong, where the error, and then add a piece of code in the portal file, open debugging:
Run the program again, the page is displayed normally, it is strange!
Turn over the source code of the thinkphp framework, see its implementation, get the following points:
1. Whendefine (' App_debug ', false);, an error appears as shown, showing only a very general note: 2, whendefine (' App_debug ', true);, what is wrong when the error is displayed as shown? Where did it go wrong? The specific context (TRACE) What is it? 3, question (1): When I did not turn on debuggingdefine (' App_debug ', false);, how to display a brief error message instead of the default general information "Page Error! Please try again later"Then?"
Locate the default profile first ./thinkphp/conf/convention.php, set the show_error_msg option to true, and then run the page to display
Template does not exist:/home/wwwroot/52php.com/jck/economic/view/index2/chargelogintype.html
Well, at least let me see the root of the problem!
Oddly enough, the ACTION on the page is Chargelogintype, and all of them are converted to lowercase. If you turn to lowercase, the view file must not be found, because the Linux server is file-name-case-sensitive.
Locate the file for the view feature ./thinkphp/library/think/view.class.php, there's a section of the code that calculates the path to the view file:
$templateFile = $this->parsetemplate ($templateFile);
When the file name is not passed, the view file with the same name as Action_name is taken.
Locate the file for the routing distribution feature ./thinkphp/library/think/dispatcher.class.php, there is a code for calculating action_name :
$urlCase = C (' url_case_insensitive ');d efine (' action_name ', defined (' Bind_action ')? Bind_action:self::getaction ($varAction, $urlCase));
That is, when you configure url_case_insensitive = true;//default false means that URL case-sensitive true means case-insensitive andAction_nane is forced to lowercase.
Summarize:
When debug define (' App_debug ', false) is not turned on, and url_case_insensitive = False , an error occurs, indicating that the view file cannot be found
4. Questions (2): When I start debuggingdefine (' App_debug ', true);, why is the page normal again?
When in debug mode, the system loads the configuration file ./thinkphp/conf/debug.php, the contents are as follows:
Debug mode The following default settings can be redefined in the app configuration directory debug.php overwrite the return array ( ' log_record ' = + true, //Logging ' Log_exception_record ' = = true, //whether to log exception information logs ' log_level ' = ' Emerg,alert,crit, Err,warn,notic,info,debug,sql ', //allow logging of log levels ' db_fields_cache ' = false,//field cache information ' Db_debug ' + = true,//open debug mode logging SQL Log ' tmpl_cache_on ' = false,//whether to open the template compilation cache, Set to False to recompile ' tmpl_strip_space ' and false every time , //whether to remove HTML spaces and line breaks in the template file ' Show_error_ MSG ' = ' = true, //Display error message ' url_case_insensitive ' and False, //URL is case sensitive;
See, there's a url_case_insensitive in it. = False, which means that the URL is case-sensitive, that is, action_name is not tampered with by the system to lowercase and remains intact.
In the calculation of the view file, the file name is correct, files also exist, so do not error!
5, the final proposal:
(1) Formal environment define (' App_debug ', false); Otherwise, the system will record a lot of log information, much more than you want to record.
Tips:
In the portal file, add the switch variable that opens debug mode, the reference code is as follows:
if ((cur_env! = ' production ') | | (Isset ($_get[' Debug ') && ($_get[' debug '] = = ' 52php '))) {define (' App_debug ', TRUE);}
(2) Locate the configuration file ./thinkphp/conf/convention.php, configured as follows:
' url_case_insensitive ' = false,//default false means URL is case-sensitive, true indicates case-insensitive ' show_error_msg ' = ' = True ',//Display error message
(3) Although the DEBUG mode is not turned on in the formal environment, because Show_error_msg = Trueis turned on, all errors will be displayed (a brief) error message, which may expose Server absolute path and other sensitive information,
Template does not exist:/home/wwwroot/52php.com/jck/economic/view/index2/chargelogintype.html
So we need to do some filtering, the absolute path is removed, shown as a relative path.
Locate the file ./thinkphp/library/think/think.class.php, locate the function static public function halt ($error) {...}, in the following code
Contains the exception page template $exceptionfile = C (' tmpl_exception_file ', NULL, Think_path. ' Tpl/think_exception.tpl ');
Before adding the code:
Filter out the service absolute path information isset ($e [' message ']) && ($e [' message '] = Str_replace (Root_path, ' ", $e [' message ']);
Fixed a bug in ThinkPHP3.2.3 throwing exception module