: This article mainly introduces the basic guide for [thinkphp]. For more information about PHP tutorials, see. Independent group:
In Apps, each group is completely independent, including models, controllers, views, configurations, and function files. This makes it easy to move and unmount groups.
The standard independent group directory structure is as follows (a Home group is used as an example ):
-- + Home group Directory
Functions-+ Common grouping function Directory
Configure Directory for the consumer-+ Conf Group
Packages-+ Lang group language pack Directory
Action-+ Action Group Action Controller Directory
Catalog-+ Model Group Model Directory
Widgets-+ Widget group Widget Directory
Extensions-+ ORG group extension Class Library Directory
Other-+... other hierarchical directories
Catalog-+ Tpl Group Template directory
Thinkphp output model and configuration
I. output of ThinkPHP 3 (important)
A. Use echo and other PHP native output methods to output data 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
Configuration:
'URL _ PATHINFO_DEPR '=>'-', // modify the URL separator
'Tmpl _ L_DELIM '=>' <{', // modify the left delimiter
'Tmpl _ R_DELIM '=>'}> ', // modify the right delimiter
'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.
'Db _ DSN '=> 'MySQL: // root: @ localhost: 3306/thinkphp', // configure database information using DSN
'Show _ PAGE_TRACE '=> true, // enable the page Trace http://w2ks.com/
The above introduces the basic guide for [thinkphp], including some content, and hopes to help those who are interested in the PHP Tutorial.