We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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:

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


16.0k
Accepted
answer

So obvious... When was this method included?

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

did you try

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

https://docs.phalcon.io/en/latest/api/Phalcon_Http_Response.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