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

How to get ContentType "application/json"

Ralf's Avatar


05 Feb, 2012 06:20 PM

Hi all,

maybe i am blind but i can´t find information how to get a response with ContentType "application/json".

I tried

$app = new Slim(); $app->contentType("application/json");

but still get ContentType text/html

Any hint?
How to change some times to text/html?


  1. Support Staff 1 Posted by Josh Lockhart on 05 Feb, 2012 06:27 PM

    Josh Lockhart's Avatar

    That should work. Example:

    $app = new Slim();
    $app->get('/foo', function () use ($app) {
        echo '{"foo":"bar"}';

    If that still does not work for you, I'll need you to send me a simple application that demonstrates this. It works here.


  2. 2 Posted by Ralf on 06 Feb, 2012 12:52 PM

    Ralf's Avatar

    Yes - it works - thanks.

    The problem was:

    i include a PHP-File with require statement. That PHP-File had some empty rows after the closing


    This takes affect in sending the empty rows into response. Because this happens before


    so - the command appears after first output and can´t take affect.

    I have solved this in delete the empty rows behind closing



  3. Support Staff 3 Posted by Josh Lockhart on 06 Feb, 2012 01:22 PM

    Josh Lockhart's Avatar

    That'll do it. Glad you got it resolved.


  4. Josh Lockhart closed this discussion on 06 Feb, 2012 01:22 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