I want to show response in json
format in controller and don't want to move in view. So, please let me any way so that I can show json
response.
Here is the code where i want to add json
headers.
$result = $this->mod_doc->get_list();
echo json_encode($result);
Just give these a try.
public function signin() {
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
//add the header here
header('Content-Type: application/json');
echo json_encode( $arr );
}
or Try this way
return $this->output
->set_content_type('application/json')
->set_status_header(200) // Return status
->set_output(json_encode(array(your array)));
$result = $this->mod_doc->get_list();
$this->output
->set_content_type('application/json') //set Json header
->set_output(json_encode($result));// make output json encoded
for more reference https://codeigniter.com/userguide3/libraries/output.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With