我的players
桌子上有三个field id
, first_name
, last_name
。显示表中每个玩家的PlayersController
have 方法index
:
public function index() {
$output = $this->Player->find('all');
$this->set(array(
'output' => $output,
'_serialize' => array('output')
));
$this->render('generic_response');
}
generic_response 是一个 XML 视图,如下所示:
<?php
$xml = Xml::fromArray(array('response' => $output));
echo $xml->asXML();
生成的 XML 是:
<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>
但我想要类似的东西:
<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>
我怎样才能做到这一点?