• Resolved seanhalley

    (@seanhalley)


    Hi there,

    I’m trying to implement CORS for my custom controller. How do I do this? Where do I set the following header:

    header( “Access-Control-Allow-Origin: *” );

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Looking at the JSON class there is an encode() function that sets the header right in the function call.

        function encode($var)
        {
            header('Content-type: application/json');
            return $this->encodeUnsafe($var);
        }

    If that works it might be possible to set a header right in your controller.

    class Seans_Controller {
    	
    	public function hello_world() {
    		header("Access-Control-Allow-Origin: *");
    		return array(
    			"message" => "Hello, world"
    		);
    	}
    }

    I just tried the above and it returned the header with the response.

    • This reply was modified 7 years, 5 months ago by monkeypunch3.
    Thread Starter seanhalley

    (@seanhalley)

    Works perfectly, thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CORS’ is closed to new replies.