Skip to content
Advertisement

Change status code in HTTP header without affecting return data in Yii 1 Restful API

I want to return data with the HTTP error code in Yii 1. So I used the following way to get the data.

JavaScript

When I use it this way API returns data with 200 error code as below enter image description here

But I want to change header status 200, so I threw exception for this, then output data also changed. I want to change only the header status.

JavaScript

enter image description here

Advertisement

Answer

Yii 1.1 does not have response abstraction, you need to use http_response_code() to change response status code:

JavaScript

Alternatively you may also use header(), but this is more tricky.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement