phpzend-frameworkzend-framework2http-status-codeszend-framework-modules

always returns 200 as a status code from zend controller


I am creating custom class to throw a error from zend as there is not built-in mechanism for this in zend. I am able to give proper response to the user. But I am having problem in returning status code for this.

    $obj =  $this->toJsonModel($result);
    $this->getResponse()->setStatusCode(403);
    error_log('Status Code' . $this->getResponse()->getStatusCode());
    return $obj;

I am getting response in $obj in Json format. Then I am setting status code to 403 for this API which I created. And then I am returning $obj from this controller.

But I am not getting 403 error when I tried this code. It's always showing 200 as a status code.


Solution

  • Some other code was causing a problem in executing this and was giving 200 every time but when I re-did some, it started working.