-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Milestone
Description
I just followed https://book.cakephp.org/5/en/views/json-and-xml-views.html#creating-xml-views and I got the missing template error.
Searched online and found this thread https://discourse.cakephp.org/t/json-view-example-from-docs-gives-missing-template-error/10536
Adding $this->viewBuilder()->setClassName("Json");
solved it for the OP, and doing the same but with Xml
solved it for me.
Maybe the docs should be updated to reflect that?
What I have now and what works for me is:
$this->viewBuilder()
->setClassName("Xml")
->setOption('rootNode', 'urlset')
->setOption('serialize', ['@xmlns', 'url']);
$this->set([
// Define an attribute on the root node.
'@xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
'url' => $urls,
]);