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.
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityI believe HeaderHelper::setHeader() is what you're looking for in the context of a plugin.
In Craft3, the correct way of setting HTTP status codes is
Craft::$app->getResponse()->setStatusCode(404);
http_response_code(404);
return $this->returnErrorJson('Something happened, try again.');