Some tips for using thinkphp in the development process will be further supplemented later, and more friends are welcome to leave a message below.
(1) do not directly use {$ _ GET in the template. id} or {$ Think. get. id}, because {$ _ GET. id} {$ Think. get. neither of the two methods is filtered, and it is easy to be XSS. We recommend that you use the I method, that is, {: I ('get. id ')}
(2) What should I do if I need to obtain the fields of a table in the database in thinkphp? Example:
$user=M('user');$fields=$user->getDbFields();
The result returns a one-dimensional array composed of table fields.
(3) If we only need to modify the value of a field during data modification, we can use the setField method instead of calling the save method every time. For example:
$user=M('user');$user->where('id=2')->setField('username','www.phpernote.com');
(4) In case of comparison, it is not necessary to use the if condition form. You can also write it in the following form:
<Eq name = "web" value = "phpernote"> value </eq> // if the value of the name variable is phpernote, <neq name = "web" value = "phpernote" is output"> value </neq> // if the value of the name variable is not equal to that of phpernote, the variable <gt name = "age" value = "5"> value </gt> // name is output. if the value is greater than 5, <egt name = "age" value = "5"> value </egt> is output. If the value of the variable is greater than or equal to 5, <lt name = "age "value =" 5 "> value </lt> // if the value of the name variable is smaller than 5, <elt name =" age "value =" 5 "> value </elt> is output. // output if the value of the name variable is less than or equal to 5
(5) In the delete operation of thinkphp, you can directly use delete without using where to perform the delete operation. For example:
$ User-> delete ('2, 5'); // delete data with a primary key of 2 and 5
(6) instructions on how to use several quick functions of thinkphp.
C operation, Operation (dynamic) configuration: Mainly used in the Action Method
Get: C ('configuration parameter ')
Set: C ('configuration parameter', new value)
Operation A: quickly create an Action object:
$ Action = A ('user'); equivalent to $ action = new UserAction ();
D operation to quickly create model data objects:
$ Model = D ('user'); equivalent to $ model = new UserModel ();
S operations and quick cache operations
Get: S ('name ')
Set: S ('name', 'value ');
Delete: S ('name', NULL );
The F operation is the same as the S operation.
(7) When the Model is named, it must be consistent with the table name in the database by default, such as PhpernoteUserModel. class. the database name corresponding to php should be 'prefix _ phpernote_user ', and the call in the program code should be: D ('phpernoteuser ');
(8) If cache is not required during development, the following definitions can be made in the entry file:
define('NO_CACHE_RUNTIME',true);
(9) If You Need To Know some additional information during development, you can define it in the configuration file. Below are several common information definitions:
'Show _ RUN_TIME '=> true, // the running time is displayed as 'show _ ADV_TIME' => true, // The detailed running time is displayed as 'show _ DB_TIMES '=> true, // display database operation times 'show _ CACHE_TIMES '=> true, // display cache operation times 'show _ USE_MEM' => true, // Display memory overhead
(10) customize the Model class and use it when instantiating the Model (the Model is the database operation class). For example:
A. Create an IndexModel. class. php under the Model directory under the Lib directory under the project directory, and then write a method play in it. The content of this method is in the loop output of 1 to 10.
B. In the Action method, you can also write it as follows:
$ Index = M ('index', 'indexmodel'); // you can add a custom model class to instantiate $ index-> play ();
The output is 1 to 10.
(11) If you need to change the default template suffix during thinkphp usage, you can make the following definitions in the configuration file:
'Tmpl _ TEMPLATE_SUFFIX '=>'. dwt '// modify the template suffix to dwt.
Articles you may be interested in
- Summary of Query Techniques in ThinkPHP
- Complete parsing of Thinkphp internal function ADSLCFUI shortcuts
- Thinkphp prints the last SQL statement
- The last record of the volist loop in the thinkphp Template
- Summary of common system variables in Thinkphp templates
- PHP implements MVC development in the simplest way, model thinking
- Thinkphp automatic verification and automatic filling are invalid Solutions
- Thinkphp Method for disabling caching