Skip to content

JSON, XML view examples from docs: “Missing Template” #7932

@mehov

Description

@mehov

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,
    ]);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions