request:
1. Request information
If you want to get the current request information, you can use the \ think \ Request class.
$request = Request::instance();
You can also use helper functions
$request = request();
You can get through this class: get URL information; set / get module / controller / operation name; get request parameters; get routing and scheduling information; set request information.
Input variable
You can complete the detection, acquisition and security filtering of global input variables through the Request object, including support for $ _GET, $ _POST, $ _REQUEST, $ _SERVER, $ _SESSION, $ _COOKIE, $ _ENV and other system variables, and file upload information.
1. You can use the has method to detect whether a variable parameter is set
Request::instance()->has('id','get'); Request::instance()->has('name','post');
Or use helper functions
input('?get.id'); input('?post.name');
1. Variable acquisition
Variable acquisition uses the following methods and parameters of the \ think \ Request class:
Variable type methods ('variable name / variable modifier', 'default value', 'filter method')
// Get the name variable of the current request Request :: instance ()-> param ( ' name ' ); // Get all the variables of the current request (filtered) Request :: instance ()-> param (); // Get All variables of the current request (original data) Request :: instance ()-> param ( false ); // Get all variables of the current request (including the uploaded file) Request :: instance ()-> param ( true );
Use helper functions to achieve:
input('param.name'); input('param.'); or input('name'); input('');
Get GET variable
Request :: instance ()-> get ( ' id ' ); // Get a get variable Request :: instance ()-> get ( ' name ' ); // Get get variable Request :: instance ()-> get (); // Get all get variables (filtered array) Request :: instance ()-> get ( false ); // Get all get variables (original array)
Use the built-in helper function input method to achieve the same function:
input('get.id'); input('get.name'); input('get.');
Get POST variable
Request :: instance ()-> post ( ' name ' ); // Get a post variable Request :: instance ()-> post (); // Get all filtered post variables Request :: instance ()- > post ( false ); // Get all post original variables
Use helper functions to achieve:
input('post.name'); input('post.');