ThinkPHP6 project basic operations (3. Controller obtains 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:
Insert picture description here
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

  1. As mentioned above $this->request->param(); (need to inherit BaseController)
  2. 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 inherit BaseController);
  3. If there is no inheritance BaseController, you can use method dependency annotation app\Requestobject
public function request(Request $request){
    
    
    dump($request->param('a',1,'intval'));
}
  1. Use helper functions
input('a');
  1. Use request()method
request()->param('a');
  1. Static method using facade mode facade
<?php

namespace app\controller;
use think\facade\Request;

class Demo
{
    
    
    public function request(){
    
    
        dump(Request::param('b'));
    }
}

Guess you like

Origin blog.csdn.net/zy1281539626/article/details/110295181