$this->response has been removed in Template controller.
So how do we set HTTP headers in acontroller exteded Template controller?
I wrote my controller which extends Template controller, and wrote
$this->response = new Response();
in before() and
public function after($response)
{
$response = $this->response;
$response->body = $this->template;
return parent::after($response);
}
Is there any better ways?
Normally you don't have to as it'll always give a 200 code by default. For any errors but still using the template you just return it like this:
return new Response($this->template, 400);
Once the action method returns anything that will be used instead of the template, in this case simply the template wrapped in a Response object with the 400 status code.