Controller gets request parameters
1. Create a new Demo controller
<?php
namespace app\controller;
use app\BaseController;
class Demo extends BaseController
{
public function request(){
dump($this->request->param());
}
}
Browser Access:
retrieve a single $this->request->param('a')
parameter: ;
Default:$this->request->param('a',1)
;
converted to an $this->request->param('a',1,'intval')
integer: ;
Second, the method of obtaining parameters
- As mentioned above
$this->request->param()
; (need to inheritBaseController
) - According to the request type, if it is a get request, you can use:, the
$this->request->get()
result is the same as above (need to inheritBaseController
); - If there is no inheritance
BaseController
, you can use method dependency annotationapp\Request
object
public function request(Request $request){
dump($request->param('a',1,'intval'));
}
- Use helper functions
input('a');
- Use
request()
method
request()->param('a');
- Static method using facade mode facade
<?php
namespace app\controller;
use think\facade\Request;
class Demo
{
public function request(){
dump(Request::param('b'));
}
}