One: module design
Single module By default, single module support, all modules with app as root namespace
Common module can be built, but not directly accessible, can be accessed in other modules, improve security
The common class can be arbitrarily inherited
II: Configuration of the TP5
1 Formula Configuration
Defining the configuration Directory
In the Portal file
Define (' Conf_path ', __dir__. /.. /conf/');
2 application Configuration
Create a new config in the previous section of the catalog. Php
return Array ();
Inside the array is the configuration item
3 Extended Configuration
Split the different configuration files into the configuration file can not be easily managed, in the Config directory to create a new extension configuration folder extra
Then create a new configuration file directly
such as qiniu.php
Configuration format is the same as on
TP5 allows database configuration to be placed directly under the Config folder (same level as config.php)
4 Scene Configuration
Different configurations used in the same scenario
Configure the App_status in config.php, and then set up the configuration of the environment in extra
5 module Configuration
Create a folder with the same module name under the Config folder, and then create a new config.php file
Module configuration of the directory and Config directory consistent, can create a new extra extension configuration, extension configuration only in the corresponding module has a role
6 Dynamic configuration
A. Configuration items in the __construct constructor in the controller that use the Assistant function Config can take effect in the controller
B. Using the helper function in a method new configuration item only takes effect in the modification method
7 Use of the Config class
To dynamically change the config configuration, you can use the Assistant function config () and use the Config class
Config (' key ', ' value ', ' scope ')
Determine if key exists
Config ('? key ');
8 Configuring and using environment variables
Three: Routing
1 entry file
Public/index.php Single Entry
2 Hidden Portal File
is both a hidden index.php
A open Apache's rewrite module, allowed all
B. htaccess configuration exists in the public directory and does not require its own configuration
2 Portal File Bindings
Bind module name, Shorten URI
For example, to bind a background module
Define Difine (' Bind_module ', ' admin ') in admin.php; Binding backend Modules
Difine (' Bind_module ', ' admin/index '); the Index controller that binds the background
Setting the ' Auto_bind_module ' =>true in the configuration file allows you to no longer define difine (' Bind_module ', ' admin ');
3 Routing
First turn on routing (default is on) Configure ' url_route_on ' =>true in the configuration file,
' Url_route_must ' =>false (true if routing must be configured to access)
Create a new routing file in the configuration file route.php
Direct Write routing rules
For example, return array (
' News/:id ' = ' index/index/news ',
);
Four: Request
1 Request Requests
A helper function request ()
Request class for B thinkphp
C Object injection, injecting the object into the method
2 Requesting Object request
A Get links in the browser
Get Domain name $request->domain ()
Get PathInfo $request->pathinfo ()
Get path $request->path ()
B Request Type
The type of the current request $request->method ();
Determine if a GET request $request->isget ()
Determine if an AJAX request $request->isajax ()
---Determine if the cell phone $request->ismobile ();
Parameters for C request
Get the parameter $request->get ()
Get all parameters (including path) $request->param ()
Get POST request $request->post ()
Get session $request->session ()
Get Cookie $request->cookie ()
D get module, CONTROLLER, operation
$request->module ();
$request->controller ();
$request->action ();
3 Input helper functions
Equivalent to the I function in tp3.2
Input (' Post.name ')
Input (' Get.name ')
Input (' Cookie.name)
Input (' Session.name)
...
You can get the various parameters in request
4 Response Object
Config (' default_return_type ', ' json '); return operation via dynamic modification of returned parameter types
More suitable for encapsulation of APIs
Type support json,xml,html (default)
For example:
Config (' default_return_type ', ' json ');
$res = [' Code ' =>200,
' Data ' =>[1,2,3,4,5,6,7,8,9]
];
return $res;
The JSON data is returned
Five views
Direct display
return view (); default is app/group name/view/Controller name/method name. html
Pass the first parameter
Return view (' name ') defaults to app/group name/view/controller name/name.html
Pass the first parameter
Return view (' name1/name2 ') defaults to app/group name/view/name1/name2.html
Return view ('./index.html ') defaults to the index,.html file in the index.php Portal file sibling directory
Passing values to the template
The second argument is in the form of an array
Return view (' name ', [' key ' = ' value '])