ThinkPHP5.1 receiving post, get parameters

We must first recognize that the requested object Requestclass

? <PHP
// use the Request class first step is to introduce him to use in the current controller
// knowledge: use the previous namespace can not have other operating spaces and so on.
App namespace \ ADMIN \ Controller;
use Think \ Request;
class Index {
  // index method is introduced in the Request
  public function index (Request Request $) {
    // represents parma receive all parameters pass over the post request or whether get request are parma can receive the parameter
    $ Data = $ request-> param ();
    // post represents only pass out post receiving mode parameter
    $ DATAl = $ request-> post ();
    // get only receive parameter represents coming out of the way get
    data2 = $ request- $> GET ();
    // If you just want to get a name value, then we can add the name to the brackets.
    Data request- = $ $> param ( 'name');
  }
 }
>?

 

 

 

In TP5.1 the judge, how 请求类型do?

? <PHP
// use the Request class first step is to introduce him to use in the current controller
// knowledge: use the previous namespace can not have other operating spaces and so on.
App namespace \ ADMIN \ Controller;
use Think \ Request;
class Index {
// index method is introduced in the Request
public function index (Request Request $) {
// request type is determined whether the POST
IF ($ request-> isPost ()) {
dump ( 'current request type POST');
}
// request type is determined whether the GET
iF ($ request-> isGet ()) {
dump ( 'current request type GET');
}
// determines whether the request type PUT
iF ($ request-> isPut ()) {
the dump ( 'current request type PUT');
}
// request type is determined whether Ajax
iF ($ request-> isajax ()) {
the dump ( 'current request type Ajax ');
}
// request type is determined whether the mobile access
iF ($ request-> isMobile ()) {
the dump ('
}
}
}
?>

Guess you like

Origin www.cnblogs.com/qcjdp/p/11281094.html