thinkphp debugging means

Source: Internet
Author: User

Using thinkphp should be mastered by the debugging means
Often see someone ask findall the return data type is what kind of problem, and error do not know what reason, in fact, is still not familiar with the thinkphp built-in debugging means and methods, throw away the IDE itself with the debug mode does not say, If you are using or planning to develop with thinkphp, then some of the following debugging-related methods you should be aware of and mastered:
1, open the debug mode Debug_mode in the project configuration file, so that you can find most of the wrong reasons. The output that may affect the verification code.
2. If you do not want to use debug mode, you can open the page trace display separately. Found that many people do not want to use debugging mode because there is the output of the page trace information, in fact, there is a misunderstanding, that debugging mode will certainly have a page trace, but in fact, debugging mode and page trace does not necessarily have a relationship, just because the debug mode is open, The default debug profile of the system turns on the page trace display, so you can define a debug profile individually for your project.
3, using the system-defined dump function, the method with Var_dump can output any type of variable information, and more conducive to viewing in the browser, for example:

  $User = D ("User"); 
$list = $User->findall ();
Dump ( $list);

4, the page trace information can only display the current page execution of SQL statements, but unable to view the Ajax mode of execution of the SQL statements inside the operation, so you can also open SQL logging sql_debug_log to record each executed SQL statement, And you can see the execution time of each SQL statement the SQL log file is located under the logs directory and automatically distinguishes the daily SQL log by date.
5, another is to execute a data operation after the suspicion of SQL execution error, you can use the model class Getlastsql method to view the last executed SQL statement, in order to analyze the specific cause of the error. For example:

$User = D ("User");
$User->id = 3;
$User->name = ' thinkphp ';
$User->save ();
echo $User->getlastsql ();
// output update Think_user set name= ' thinkphp ' where id=3;

6, when you need to debug a piece of code run time, you can use the system-provided Debug_start ($label) and Debug_end ($label) method, for example:

Debug_start (' demo ');
Here is your code snippet ....
Debug_end (' demo ');

thinkphp debugging means

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.