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

Setting headers with Response and then using Halt

kishore's Avatar


09 Apr, 2012 05:23 PM


Just updated the code and tried this. But no dice. :-(

$app = Slim::getInstance('CommAPI');
$response = $app->response();

//Generate Response headers
$response->header('Content-Type', $r_content_types[$content_type]);

// Set the common headers
$response->header('Content-Length', '500');

// Generate response based on response type
$responseBody = array('message'=> $body);

if (array_key_exists($code, $r_status_code_msgs)) {
    echo "asssss";
    $app->halt($code, $r_status_code_msgs[$code]);
} else { // send the default status code
    echo "Bass";
    $app->halt(DEFAULT_RESPONSE_CODE, $r_status_code_msgs[DEFAULT_RESPONSE_CODE]);
  1. 1 Posted by Kishore on 09 Apr, 2012 05:24 PM

    Kishore's Avatar

    The "echo" stmt will be removed. Thats just for testing.

  2. 2 Posted by Kishore on 09 Apr, 2012 05:37 PM

    Kishore's Avatar

    I guessI see what is happening here. The 2nd parameter of Halt is actually body of the response. I was assuming, its the status message. like Unauthorized, Not implemented, etc. I see that I do NOT have to worry about the actual status message. The message is sent based on the status code.

    Seems to be working fine.


  3. Support Staff 3 Posted by Josh Lockhart on 09 Apr, 2012 05:38 PM

    Josh Lockhart's Avatar

    Yep. Be sure you read through the online documentation. The source code is also well documented.

  4. Josh Lockhart closed this discussion on 09 Apr, 2012 05:38 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