Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How can I retrieve response status code

    $app = new Phalcon\Mvc\Micro();
    ... 
    $app->after(
        function () use ($app) {
            $records = $app->getReturnedValue();
            ...
            // At this time I want to know what is the response status code!
            // Ex: in some part of the application I called: $response->setStatusCode(404, "Not Found");
            ...
        })

This way:

$app['response']->setStatusCode(404, "Not Found");

Hello Andy.

I want to get actual status code, not set.

This way:

```php $app['response']->setStatusCode(404, "Not Found"); ```



12.3k
Accepted
answer

So obvious... When was this method included?

BTW, this response is always FALSE. Curious...

did you try

$app['response']->getStatusCode();

https://docs.phalconphp.com/en/latest/api/Phalcon%5Http%5Response.html

is since 2.0.0 and it returns this->getHeaders()->get("Status");

https://github.com/phalcon/cphalcon/blob/master/phalcon/http/response.zep#L228