2

I'm developing a REST API using Zend Framework 1.12.3. I would like to know whether it's possible to set a HTTP response code from inside a Handler.

I'm using the Handler to check the "Accept" header. In case the requested format type is not supported, I should set a 415 HTTP error (Unsupported Media Type). However, I'm not able to set a response code from inside the Handler.

1 Answer 1

4

What do you mean by handler?

You can set a response code anywhere you have access to the Response object.

Technically, you can access the Response object nearly anywhere (after Bootstrap, at least) using:

$response = Zend_Controller_Front::getInstance()->getResponse();

The set your response code using:

$response->setHttpResponseCode($code);

It's most natural to do this in controllers since each controller already has a reference to the Response object:

$this->_response
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.