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.

5

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

3
HeaderHelper::setHeader(array('status' => 404));
3

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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