Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok I see what happens. there´s an issue between cakePHP query result array construction and the form that the xml helper expect to see it for a proper creation of the xml file. For example you construct an array for get all your posts (<code>$posts = $this-&gt;Post-&gt;find('all');</code>)</p> <p>This is what you get:</p> <pre><code> $posts = array( 'post' =&gt; array( array( 'id' =&gt; '1', 'tittle' =&gt; 'The title' ), array( 'id' =&gt; '2', 'tittle' =&gt; 'A title once again' ) ) ); </code></pre> <p>this what an instruction like <code>$xml = Xml::build($xmlPosts);</code> on cakePHP expect on, for example, in a index.ctp file under your xml folder, inside View/Posts:</p> <pre><code>$posts = array( 'posts' =&gt; array( 'post' =&gt; array( array( 'id' =&gt; '1', 'tittle' =&gt; 'The title' ), array( 'id' =&gt; '2', 'tittle' =&gt; 'A title once again' ) ) ) ); $xml = Xml::build($post); </code></pre> <p>The problem yields in that with XML parser needs a root element in the array.</p> <p>the documentation on cakePHP dosen´t tell you that. So be careful on follow the example about REST services if you are a beginner on the cookbook. </p> <p>You can fix the issue doing so array rearrangement in the index.ctp xml constructor. Something like this:</p> <pre><code>&lt;?php $xmlPosts = array('posts' =&gt; array('post' =&gt; $posts)); $xml = Xml::build($xmlPosts); echo $xml-&gt;saveXML(); ?&gt; </code></pre> <p>I know is not the optimal solution. But I'm open to more thoughtful answers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload