Codeigniter 4 – InComing Request Class with Example
Incoming Request Class
- The Incoming Request class provides methods to retrieve information about the incoming request.
- It can be accessed using the request() function.
Retrieving Request Headers
- Use the getHeader() method to retrieve a specific request header.
Example:
$header = request()->getHeader('Content-Type');
Retrieving Request Body
- Use the getBody() method to retrieve the request body.
Example:
$body = request()->getBody();
Retrieving Request Method
- Use the getMethod() method to retrieve the request method (e.g. GET, POST, PUT, DELETE).
Example:
$method = request()->getMethod();
Retrieving Request URI
- Use the getUri() method to retrieve the request URI.
Example:
$uri = request()->getUri();
Retrieving Request Segments
- Use the getSegments() method to retrieve the request URI segments.
Example:
$segments = request()->getSegments();
Retrieving Request Query Parameters
- Use the getQueryParams() method to retrieve the request query parameters.
Example:
$params = request()->getQueryParams();
Retrieving Request Post Data
- Use the getPost() method to retrieve the request post data.
Example:
$post_data = request()->getPost();
I hope this helps! Let me know if you have any further questions or need more information.
Note: The Incoming Request class in CodeIgniter 4 provides a simple and intuitive way to retrieve information about the incoming request. It can be used to build robust and flexible applications.