The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Support extensions .json .xml

stil's Avatar


25 Jan, 2012 01:04 PM

How can I implement extensions in url, like

Or, is there a way for processing returned value by anonymous function in order to output it in desirable format?
For example
$slim->get('/hello/world',function() { return array('message'=>'bla bla'); });

I would like be able to convert it to either JSON or XML format.

  1. Support Staff 1 Posted by Josh Lockhart on 25 Jan, 2012 01:19 PM

    Josh Lockhart's Avatar

    I intend to add content negotiation features to Slim in the next few versions. For now, you'll need to write middleware to do this for you.

  2. 2 Posted by hexa2k9 on 25 Jan, 2012 08:18 PM

    hexa2k9's Avatar

    I'm running that 'in some sort' too. I've got a route $app->get('/nickinfo/:nick/:format/' function foo() { ... });. So I've got the format as a parameter; that's running just fine for me. In case it's not given I answer in json format. It's not running in 'rails style' (e.g. append the format using a dot or running real content negotiation), but it's just fine for me.

  3. Support Staff 3 Posted by Josh Lockhart on 26 Jan, 2012 08:32 PM

    Josh Lockhart's Avatar

    What @hexa2k9 is doing is likely the best approach at this time until native content negotiation support is added to the framework. Closing.

  4. Josh Lockhart closed this discussion on 26 Jan, 2012 08:32 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac