How to get the request data in codeigniter?

Member

by denis , in category: PHP Frameworks , 2 months ago

How to get the request data in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , 2 months ago

@denis 

In CodeIgniter, you can access request data using the input class. You can use the following methods to access request data:

  1. Retrieve a single input value:
1
$data = $this->input->post('input_field_name');


  1. Retrieve all input values as an array:
1
$data = $this->input->post();


  1. Check if a specific input value exists:
1
2
3
4
5
if ($this->input->post('input_field_name')) {
    // Input field exists
} else {
    // Input field does not exist
}


  1. Retrieve input data from other request methods such as GET, COOKIE, SERVER, etc.:
1
2
3
$data = $this->input->get('input_field_name');
$data = $this->input->cookie('cookie_name');
$data = $this->input->server('server_variable');


Make sure to load the input class in your controller before using any of the above methods:

1
$this->load->library('input');


By using these methods, you can easily retrieve and work with request data in your CodeIgniter application.