It's not that simple. Even though the array is changed, will still give
something like:
<response> <players>
<Player>
<id>2</id>
<first_name>Ciro</first_name>
<second_name>Spee</second_name>
</Player> </players>
<players> <Player> <id>3</id> <first_name>Ugo</first_name>
<second_name>Ridi</second_name> </Player></players>
</response>
I have the same problem. So I tried to isolate the problem, and I think it
is on the array returned by the Model class.
The array returned by the function find is:
array(
(int) 0 => array(
'Project' => array(
'id' => '1'
)
),
(int) 1 => array(
'Project' => array(
'id' => '2',
)
)
)
And the one which is cited in the documentation for XML
(http://book.cakephp.org/2.0/en/core-utility-libraries/xml.html#transforming-an-array-into-a-string-of-xml)
is:
array(
'projects' => array(
'project' => array(
(int) 0 => array(
'id' => (int) 1
),
(int) 1 => array(
'id' => (int) 2
)
)
)
)
Even after the XmlView._serialize() insert the <response> and "<output>"
nodes, still have differences.
I'm using the 2.3.0 version, and there is no issue about this
on http://cakephp.lighthouseapp.com/dashboard
This is really a problem?
Em quarta-feira, 23 de janeiro de 2013 22h26min36s UTC-2, jsundquist
escreveu:
>
> Change your set array to be players instead of output.
> On Jan 23, 2013 6:01 PM, "Mariano C." <[email protected] <javascript:>>
> wrote:
>
>> I have the players table with three field id, first_name, last_name. The
>> PlayersController have method index that show every player in the table:
>>
>> public function index() {
>> $output = $this->Player->find('all');
>> $this->set(array(
>> 'output' => $output,
>> '_serialize' => array('output')
>> ));
>> $this->render('generic_response');
>> }
>>
>> and the generic_response is an XML view that look like this:
>>
>> <?php
>> $xml = Xml::fromArray(array('response' => $output));
>> echo $xml->asXML();
>>
>> The resulting XML is:
>>
>> <response>
>> <output>
>> <Player>
>> <id>2</id>
>> <first_name>Ciro</first_name>
>> <second_name>Spee</second_name>
>> </Player>
>> </output>
>> <output>
>> <Player>
>> <id>3</id>
>> <first_name>Ugo</first_name>
>> <second_name>Ridi</second_name>
>> </Player>
>> </output></response>
>>
>> but I want something like:
>>
>> <response>
>> <players>
>> <Player>
>> <id>2</id>
>> <first_name>Ciro</first_name>
>> <second_name>Spee</second_name>
>> </Player>
>> <Player>
>> <id>3</id>
>> <first_name>Ugo</first_name>
>> <second_name>Ridi</second_name>
>> </Player>
>> </players></response>
>>
>> How can I do this?
>>
>> --
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>.
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>
>>
>>
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.