Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
JSONP support in Controller_Rest
  • Hey, I may be missing something but: I'm creating an API that needs to work crossdomain but Controller_Rest doesn't seem to support JSONP. I could have a go at implementing it, but you guys probably know more about jsonp than I. What do you think? Rob :)
  • Have a go at it, you may surprise yourself :) I manage to surprise myself a lot... just code to spec not preference and you should do well...
  • I had a go https://github.com/unforeseen/core/tree/develop Not sure if I did it right, I'm new to both git and fuel!
  • Looks like it should work... check the docs on this site for coding standards and test this a bit and you're good to go!
    /**
    * To JSONP conversion
    *
    * @param mixed $data
    * @return string
    */
    public function to_jsonp($data = null)
    {
     $callback = \Input::get_post('callback', null));
    
     is_null($callback) and $callback = 'response';
    
     return $callback.'('.$this->to_json($data).')';
    }
    

    Although this may be a little more concise :)
  • Also, check out the docs for "extending core classes" to see the proper way to implement this into your app :)
  • Hi!

    I'm also trying to implement an API that needs to work cross-domain using JSONP. It seems to me that this conversation is no longer relevant to the latest version of Fuel. My understanding is that you would now need to use the Format class to forge a create a new JSON object for the callback and then use that in the response.

    Can anybody point me to an example of how to add JSONP functionality to a REST controller?

    Cheers,

    Sebastian

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion