Thinkphp parameter delivery method (base)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.