5

I'm trying to set a 404 HTTP status response code for an ajax controller action in a plugin.

Yii has a response object where the code can be set, but I can't find a way to access it from craft.

4 Answers 4

6

I believe HeaderHelper::setHeader() is what you're looking for in the context of a plugin.

0
6

In Craft3, the correct way of setting HTTP status codes is

Craft::$app->getResponse()->setStatusCode(404);

3
HeaderHelper::setHeader(array('status' => 404));
1
http_response_code(404);
return $this->returnErrorJson('Something happened, try again.');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.