Created
August 29, 2018 08:23
-
-
Save aaryadev/ebb94a1dba9c947b764f1af25306adca to your computer and use it in GitHub Desktop.
Code igniter API Header setting for JSON output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Api extends CI_Controller { | |
function __construct(){ | |
parent:: __construct(); | |
$this->output->set_header("Access-Control-Allow-Origin: * "); | |
$this->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); | |
$this->output->set_header("HTTP/1.0 200 OK"); | |
$this->output->set_header("HTTP/1.1 200 OK"); | |
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); | |
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate"); | |
$this->output->set_header("Cache-Control: post-check=0, pre-check=0"); | |
$this->output->set_header("Pragma: no-cache"); | |
$this->output->set_content_type('application/json'); | |
} | |
public function index(){ | |
$this->output->set_output(json_encode($data)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment