Use thinkphp to do the development process of some skills summary, later found that will continue to add, but also welcome more friends in the following message to add.
(1) Do not use {$_get.id} or {$Think. get.id} directly in the template, because {$_get.id} {$Think. get.id} These two ways are not filtered and susceptible to XSS. It is recommended to use the I method, i.e.: {: I (' get.id ')}
(2) What if you need to get a field for a table in a database in thinkphp? Examples are as follows:
$user =m (' user '); $fields = $user->getdbfields ();
The result returns a one-dimensional array consisting of a table field.
(3) in the process of data modification if we only need to modify the value of a field, we can use the SetField method without having to call the Save method each time, for example:
$user =m (' user '), $user->where (' id=2 ')->setfield (' username ', ' www.phpernote.com ');
(4) When it comes to comparisons, it is not necessary to use if condition in this form, and can also be written as follows:
Value//name variable is equal to phpernote the value of output
value//name variable is not equal to Phpernote output
The value//name variable is greater than 5
for the output value//name variable is greater than or equal to 5
value
The value of the name variable is less than 5 and
The output value//name variable is less than or equal to 5
(5) In the thinkphp delete operation can not use where the delete directly to perform the deletion, for example:
$User->delete (' 2,5 ');//delete data with primary keys of 2 and 5
(6) A description of the usage of several quick-action functions for thinkphp.
C operation, operation (dynamic) configuration: Mainly used in the action method inside
Get: C (' config parameter ')
Setting: C (' config parameter ', new value)
A action to quickly create an action object:
$action =a (' User '); Equivalent to $action =new useraction ();
D operation to quickly create a model data object:
$model =d (' User '); Equivalent to $model =new Usermodel ();
s operation, fast action caching method
Get: S (' name ')
Settings: S (' name ', ' value ');
Delete: S (' name ', NULL);
F operation, fast file data saving method, using the same method as the S operation.
(7) Model naming, the default is to match the table name in the database, such as the PhpernoteUserModel.class.php corresponding database name should be ' prefix _phpernote_user ', the call in the program code should be: D (' Phpernoteuser ');
(8) In the development process, if you do not need to cache, you can define the following in the portal file:
Define (' No_cache_runtime ', true);
(9) In the development process if you need to know some additional information, can be defined in the configuration file, the following is a few more common information definition methods:
' Show_run_time ' =>true,//run time display ' Show_adv_time ' =>true,//show verbose run time ' show_db_times ' =>true,// Show database Operations ' Show_cache_times ' =>true,//show cache operation Count ' Show_use_mem ' =>true,//display memory overhead
(10) To customize the model class and use it when instantiating models (models are database operation classes), for example:
A, in the project directory under the Lib directory under the model directory to create a IndexModel.class.php, and then write a method play, this method content body for the loop output 1 to 10.
b, then in the action method, you can also write:
$index =m (' index ', ' Indexmodel ');//Here you can add a custom model class to instantiate $index->play () together;
Then the output is 1 to 10.
(11) In the process of using thinkphp, if you need to change the default template suffix name, you can define the following in the configuration file:
' Tmpl_template_suffix ' = '. DWT '//change the name of the template suffix to a DWT
Articles you may be interested in
- A summary of query techniques in thinkphp
- Full analysis of Adslcfui shortcut method for thinkphp internal function
- thinkphp print the last SQL statement
- The last record in the thinkphp template that determines the volist loop
- Summary of System variables commonly used in thinkphp templates
- PHP implements the simplest method of MVC development, model thinking
- thinkphp Automatic validation and auto-fill Invalid workaround
- thinkphp how to turn off caching
http://www.bkjia.com/PHPjc/764116.html www.bkjia.com true http://www.bkjia.com/PHPjc/764116.html techarticle use thinkphp to do the development process of some skills summary, later found that will continue to add, but also welcome more friends in the following message to add. (1) Do not use in the template directly ...