I mainly learned this afternoon the routing part of thinkphp5.0, I summarize the following I mainly learned the knowledge points:
Route definition:
There are two ways of doing this:
(1). Dynamic registration:
eg
Route::rule (' Hello ', ' Index/index/hello ', ' GET ');
(2) Profile:
eg:
Return [
' __pattern__ ' = = "
' name ' = ' \w+ ',
",
' [Hello] ' = ' = '
': id ' = ' [' Index/hello ', [' method ' = ' get '], [' id ' = ' = ' \d+ '],
": name ' = = [' Index/hello ', [' method ' = ' post ']],
",
];
request type:
| type |
Description |
| GET |
GET request |
| POST |
POST request |
| PUT |
Put request |
| DELETE |
Delete request |
| * |
Any request type |
< Span style= "COLOR: #808080" >
Eg:
/span>
route::get ( ' New/:id ', ' News/read '); //definition Get request Routing Rule route::p Ost ( ' New/:id ', news/ Update '); //define post request routing rules route::p ut ( ' New/:id ', News/update '); //define put request routing rules route::d elete ( ' New/:id ', News/delete '); //defines the delete request routing Rule route::any ( ' New/:id ', News/read '); //all requests support routing rules
methods to get parameters [three]:
1). Corresponding to the variables in the method
public function hello ($id, $name Span style= "COLOR: #9876aa" >)
{
echo $id;
Echo $name; < Span style= "COLOR: #cc7832" >
} < Span class= "hljs-string" >
2). The Request Object
Requeset::instance=>param ();//gets all parameters [array of result types], no requests type;
Requeset::instance=>param (' name ');//Get a single parameter [i.e.: fill in the variable name directly];
Requeset::instance=>get ();//get the following parameters;
Requeset::instance=>route ();//Get the parameters inside the route;
Requeset::instance=>post ();//Get POST request parameters
Eg:
public function hello ( Span style= "COLOR: #9876aa" > )
{
$res =request:: Instance ()->param () ;
var_dump ( $res ) ;
}
Dependency Injection method
public function hello (request $request )
{
$res = $request -> param () Var_dump ( $res) ;
}
< Span style= "COLOR: #cc7832" > Span style= "color: #ffc66d; Font-style:italic ">
3). Use the input helper function
input (' param ');//Get all result array
input (' param.name ');//Get name
Input (' get.name '); Get post mode
input (' get.name ');//Get Get method
< Span class= "hljs-string" >&NBSP;
< Span class= "hljs-string" >&NBSP;
Thinkphp parameter delivery method (base)