You may have misread, and I might be misunderstanding the functionality of withStatus
. Do you mean your example returns a 404 response and not a 200 response as you mentioned?
If you do return $response->withStatus(404);
I would assume this returns a 404 response.
Either way, I believe I have solved my problem. This seems to have worked:
(Where $this->templates
is an instance of League\Plates\Engine
)
$template = $this->templates->render('TemplateFile', ['param' => $param]);
return $response->withStatus(404)->write($template);
I was under the assumption that you must ->getBody()
before you can ->write()
to the response, but this doesn’t seem to be the case. I’m not sure what the difference is, but using ->getBody()
beforehand was not giving the proper response code. If anyone can shed light on this, that would be great.