This article mainly introduces the ThinkPHP debugging mode and logging usage. For more information, see ThinkPHP.
This article describes how to use ThinkPHP debugging mode and logging. this function plays an important role in ThinkPHP project development. it is necessary to understand and master it. The specific method is as follows:
1. you can set it in config. php, which is disabled by default.
The method for enabling is as follows:
'APP_DEBUG' => true
Open the \ ThinkPHP \ Common \ debug. php file to view the default debug settings as follows:
Return array ('log _ record' => true, // perform log record 'log _ RECORD_LEVEL '=> array ('error', 'Alert', 'crit ', 'err', 'warn', 'notic', 'info', 'debug', 'SQL '), // The log level that can be recorded: 'DB _ FIELDS_CACHE '=> false, // The database field caches 'show _ RUN_TIME' => true, // Display 'show _ adv_time' => true, // display the detailed running time 'show _ DB_TIMES '=> true, // display the number of database queries and writes 'show _ CACHE_TIMES '=> true, // display the number of cache operations 'show _ USE_MEM' => true, // display the memory overhead 'show _ PAGE_TRACE '=> true, // display the page Trace information. the Trace file definition and Action operation value 'app _ FILE_CASE' => true, // check whether the file's case sensitivity is valid for Windows );
Note: The DB_FIELDS_CACHE database field cache is disabled by default. if it is enabled, the file cache will be generated in the Runtime \ Data folder and the new field is added after the table is modified, this cache cannot record your operations. you need to manually delete the table once before modification is successful.
After 'app _ debug' => true, the following DEBUG prompt appears when you access the page:
If you only want to display some prompts, such as running time and memory overhead,
You can set it in config. php, for example:
// 'App _ debug' => true, // The DEBUG mode switch 'show _ RUN_TIME '=> true, // The running time is displayed as 'show _ adv_time' => true, // display the detailed running time 'show _ DB_TIMES '=> true, // display the database operation times 'show _ CACHE_TIMES' => true, // display cache operation count 'show _ USE_MEM '=> true, // display memory overhead
The prompt information is as follows:
2. Custom page Trace information: \ ThinkPHP \ Tpl \ PageTrace. tpl. php
Custom Method 1: Add a trace. php file to the directory of config. php at the same level. the code is as follows:
<? Php return array {'current server information' =>$ _ SERVER ['remote _ ADDR '] ,};?>
Custom Method 2: Add the following in the Action method:
$ This-> trace ('debug test', '123 ');
3. output debugging method:
Halt ('aaaaaaa'); // output aaaaaa and interrupt program execution
4. model debugging: displays SQL statements.
$ User = new Model ('user'); $ User-> find (1); echo $ User-> getLastSql (); // output the last executed SQL statement
5. Log records \ ThinkPHP \ Lib \ Think \ Core \ Log. class. php
Set in config. php
'Log _ RECORD '=> true, // enable the log record 'log _ RECORD_LEVEL' => array ('error', 'Alert ', 'error '),
I hope this method will be helpful to you.