Check the migration guide:
RequestHandlerComponent
now switches the layout and template based on the parsed extension or Accept
header in the beforeRender()
callback instead of startup()
.
Cookbook > Appendices > 3.1 Migration Guide > RequestHandlerComponent
So this means that what you set there (wherever that is, but for sure it's not in the Controller::beforeRender()
callback), will be overwritten after the controller action ran, and before the view is being rendered.
There are various ways to handle this.
Make proper use of the request handler component, that is, enable extension parsing and supply an extension in your URL, or send a proper Accept
header. That way the component will set the proper response type.
This is the recommended way!
See also Cookbook > Views > JSON and XML views
Set the RequestHandlerComponent::$ext
property, which is being evaluated before rendering, and will cause the request handler component to set the response type accordingly,
$this->RequestHandler->ext = 'xml';
Use RequestHandlerComponent::renderAs()
to instruct the request handler component to use the configured XML view, which will override the "wrong" type set in the beforeRender()
callback.
$this->RequestHandler->renderAs($this, 'xml');
Do not use the request handler component and set the response type directly on the response object.
$this->response->type('xml');