Return http 500 with Slim framework

php, slim

Solution

The `$app->response()->status(500);` is correct, see the docs here.

Check to make sure you're calling `$app->run();` after setting the status, this will prepare and output the response code, headers and body.

Edit, make sure you define a route or Slim will output the 404 response, this works:

require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

$app->response()->status(500);

$app->get('/', function () {
    // index route
});

$app->run();

Problem

If somethings goes bad in my API i want to return a http 500 request. ``` $app = new Slim(); $app->halt(500); ``` It still return a http 200. If i run this code: ``` $status = $app->response()->status(); echo $status; //Here it is 200 $status = $app->response()->status(500); echo $status; //Here it is 500 ``` it stills give me a http 200

Original source