The first method of using the request
Add a request reference to the controller head
Then call the ' instance ' class in the method
Then in the call method:
PublicfunctionIndex($name =' name ') {$request = Request::instance ();Echo' Request method: '.$request->method ().' <br/> ';Echo' Resource type: '.$request->type ().' <br/> ';Echo' Access IP: '.$request->ip ().' <br/> ';Echo' Is the AJAX request: '. Var_export ($request->isajax (),true).' <br/> ';Echo' Request parameters: '; Dump$request->param ());Echo' Request parameter: contains only name '; Dump$request->only ([' name ']);Echo' Request parameter: Exclude name '; Dump$request->except ([' name ']);Echo' Resource type: '.$request->type ().' <br/> ';Echo' <br/> operation: '.$request->action ();Echo' Get current domain name: '.$request->domain ().' <br/> ';Get Current Portal FileEcho' Get current entry file: '.$request->basefile ().' <br/> ';Get current URL address, without domain nameEcho' Get current URL address, without domain name: '.$request->url ().' <br/> ';Get the full URL address that contains the domain nameEcho' Get the full URL address containing the domain name: '.$request->url (true).' <br/> ';Get URL address does not contain query_stringEcho' Get URL address does not contain query_string: '.$request->baseurl ().' <br/> ';Gets the root address of the URL accessEcho' Get the root address of the URL access: '.$request->root ().' <br/> ';Gets the root address of the URL accessEcho' Get the root address of the URL access: '.$request->root (true).' <br/> ';Get the Path_info information in the URL addressEcho' Get the Path_info information in the URL address: '.$request->pathinfo ().//get the Path_info information in the URL address, without the suffix echo $request->path (). //get the suffix information in the URL address echo Gets the suffix information in the URL address: '. $request->ext (). ' name ', ' thinkphp '); Cookie::set ( ' name ', ' thinkphp2 '); Dump ( $request->route ()); Dump ( $request->dispatch ()); echo session::get ( ' name ');}
/span>
The result is:
Because the screen is not large enough so there is still a part of the not up, but everyone just know how to use it.
The second method of
This method is relatively simple but also a little bit cumbersome, he simply refers to the controller class and then inherit it can be called without having to refer to the request as above and then call $request = Request::instance () in the method; Before they can be used.
Reference controller This is the same as the quote request above.
use think\Controller
And then inherit the controller.
Finally call ' request '
Is it a little more troublesome than method one? Every time you call, you need to add $this->request to the front.
The overall code is:
PublicfunctionTest(){Get current domain nameEcho' Domain: '.$this->request->domain ().' <br/> ';Get Current Portal FileEcho' File: '.$this->request->basefile ().' <br/> ';Get current URL address without domain nameEcho' URL: '.$this->request->url ().' <br/> ';Get the full URL address that contains the domain nameEcho' URL with domain: '.$this->request->url (true).' <br/> ';Get current URL address does not contain query_stringEcho' URL without query: '.$this->request->baseurl ().' <br/> ';Gets the root address of the URL accessEcho' Root: '.$this->request->root ().' <br/> ';Gets the root address of the URL accessEcho' Root with domain: '.$this->request->root (true).' <br/> ';Get the Path_info information in the URL addressEcho' PathInfo: '.$this->request->pathinfo ().' <br/> ';Get path_info information in URL address without suffixEcho' PathInfo: '.$this->request->path ().' <br/> ';Gets the suffix information in the URL addressEcho' Ext: '.$this->request->ext ().' <br/> ';EchoThe current module name is.$this->request->module ();EchoThe current controller name is.$this->request->controller ();EchoThe current operation name is.$this->request->action ();Echo' Request method: '.$this->request->method ().' <br/> ';Echo' Resource type: '.$this->request->type ().' <br/> ';Echo' Access IP address: '. $this->request->ip (). ' <br/> '; Echo ' is Ajax request: '. Var_export ($this->request->isajax (), true). ' <br/> '; echo ' request parameter: '; dump ($this->request->param ()); echo ' request parameter: contains only name '; Dump ($this->request->only ([' name '])); echo ' request parameter: Exclude name '; Dump ($this->request->except ([' name ']));}
The final result diagram:
Use of Request object in ThinkPHP5.0 and common actions