I am trying to build a nice REST API for my website and I had never tried it through CakePHP. I started to follow the (short) instructions, however, the way it works looks totally different from what I can read in the Cookbook.
I use CakePHP 2.2.1.
Here's what I've done so far:
app/Controller/OrdersController.php
<?php
class OrdersController extends AppController {
public function fetch($accountId) {
$this->loadModel('Account');
$this->Account->id = $accountId;
$orders = $this->Order->find('all', array(
'conditions' => array('Order.account_id' => $accountId)
));
$response = $orders;
$this->set(compact('response'));
}
}
app/View/Orders/xml/fetch.ctp
<?php
$xml = Xml::fromArray(array('orders' => $orders));
echo $xml->asXML();
I tried this with the first account and everything was fine
Ouput:
<orders>
</orders>
Everything is fine with an account that has one order.
However, with an account that has several orders, this doesn't work anymore.
Expected output:
<orders>
</orders>
What I get:
This page contains the following errors:
error on line 1 at column 367: Entity 'nbsp' not defined
Below is a rendering of the page up to the first error.
I assume that Xml::fromArray() doesn't accept multiple numeric keys. Or something like this. I don't mind editing my PHP array to get he XML I expect but I really don't know how I should write my array for this :-(
Any help is welcome.
Thank you!!
Alex
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
No comments:
Post a Comment