The output of the thinkPHP template and the use of the model. A. Use echo and other PHP native output methods to output B on the page. Use assign method c to distribute variables through the display method, modify the left and right delimiters, and modify the configuration file. echo and other PHP native output methods are output on the page
B. output through the display method
You can use the assign method to allocate variables.
C. modify the left and right delimiters
Do not modify the configuration items in the configuration file
'Tmpl _ L_DELIM '=>' <{', // modify the left delimiter
'Tmpl _ R_DELIM '=>'}> ', // modify the right delimiter
II. Use of ThinkPHP 3 models (important)
You need to operate the database in the form of new Model (table name) in the method
$ M = new Model ('user ');
$ Arr = $ m-> select ();
'Db _ type' => 'mysql', // Set the database TYPE
'Db _ host' => 'localhost', // Set the HOST
'Db _ name' => 'thinkphp', // Set the database NAME
'Db _ user' => 'root', // Set the USER name
'Db _ pwd' => '', // Set the password
'Db _ port' => '123', // Set the PORT number
'Db _ prefix' => 'TP _ ', // you can specify a table PREFIX.
You can also use the DSN method for configuration.
'Db _ DSN '=> 'MySQL: // root: @ localhost: 3306/thinkphp', // configure database information using DSN
If both methods exist at the same time, the priority is given to the DSN method.
There is also a simple and practical model method
M () is equivalent to new Model ();
$ M = M ('user ');
$ Arr = $ m-> select ();
A model instance can be used to operate on data. The operation generally involves adding, deleting, modifying, and querying the database CURD.
Add-C Create $ m-> add ()
Delete-D delete $ m-> Delete ()
Change-U Update $ m-> save ()
Query-R Read $ m-> select ()
III. Supplement (understanding)
A. The template can traverse arrays.
<{$ Vo. id}> ---- <{$ vo. username}> ----- <{$ vo. sex}>
B. We can enable page_trace in the debugging function.
1. enable debugging
// 3. enable the debugging mode
Define ('app _ debug', true );
2. we need to set the configuration file to enable page trace
'Show _ PAGE_TRACE '=> true, // enable page Trace
Echo and other PHP native output methods output B on the page. if you want to allocate variables through the display method output, you can use assign method c to modify the left and right delimiters. you need to modify the configuration file...