title: Life cycle meta:

  • name: description content: easyswoole,Life cycle
  • name: keywords content: swoole|swoole extension|swoole framework|easyswoole|Life cycle

Life cycle

The Request object exists in the system in singleton mode, and is automatically created when the client HTTP request is received, until the request ends automatically. The Request object is fully compliant with all the specifications in [PSR7] (psr-7.md).

Method list

getRequestParam()

Used to get the parameters submitted by the user through POST or GET (Note: If POST and GET have the same key name parameter, GET will be used). Example:

  1. // In the controller, the Request object can be obtained via $this->request()
  2. // $request = $this->request();
  3. $data = $request->getRequestParam();
  4. var_dump($data);
  5. $orderId = $request->getRequestParam('orderId');
  6. var_dump($orderId);
  7. $mixData = $request->getRequestParam("orderId","type");
  8. var_dump($mixData);

getSwooleRequest()

This method is used to get the current swoole_http_request object.

PSR-7 Specifications Common Methods in the ServerRequest Object

getCookieParams()

This method is used to obtain the cookie information in the HTTP request.

  1. $all = $request->getCookieParams();
  2. var_dump($all);
  3. $who = $request->getCookieParams('who');
  4. var_dump($who);

getUploadedFiles()

This method is used to obtain all file information uploaded by the client.

  1. $img_file = $request->getUploadedFile('img');//Get an upload file that returns an object of \EasySwoole\Http\Message\UploadFile
  2. $data = $request->getUploadedFiles();//Get all uploaded files and return an array containing the \EasySwoole\Http\Message\UploadFile object
  3. var_dump($data);
  4. #### \EasySwoole\Http\Message\UploadFile对象:

Click to view [UploadFile object] (./uploadFile.md)

getBody()

This method is used to get the raw data submitted by POST in non-form-data or x-www-form-urlenceded encoding format, which is equivalent to $HTTP_RAW_POST_DATA in PHP.

Get get content

  1. $get = $request->getQueryParams();

Get post content

  1. $post = $request->getParsedBody();

Get raw content

  1. $content = $request->getBody()->__toString();
  2. $raw_array = json_decode($content, true);

Getting the head

  1. $header = $request->getHeaders();

Get the server

  1. $server = $request->getServerParams();

Get a cookie

  1. $cookie = $request->getCookieParams();