Re: REST, Xml::fromArray() and find('all')

2012-08-31 Thread Alexandre Leprêtre
Thanks for your answer. Yes indeed it doesn't behave the way the manual 
says it should.

For now I will use an alternative ;-)

Le jeudi 23 août 2012 11:47:02 UTC+1, Alexandre Leprêtre a écrit :
>
> Hi everyone,
>
> 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*
>  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* 
>  $xml = Xml::fromArray(array('orders' => $orders));
> echo $xml->asXML();
>
> I tried this with the first account and everything was fine
>
> *Ouput:*
> 
> 
> 502cc39f-5b74-4a25-9bb2-670458d0d2b2
> 96277
> 502cc39d-8640-465a-b0da-670458d0d2b2
> 2012-08-16 09:55:43
> 2012-08-16 09:55:43
> 
> 
>
> 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:*
> 
> 
> 502cc39f-66eb-59d2-2337-670458d0d2b2
> 96255
> 502cc39d-6325-ad25-5b64-670458d0d2b2
> 2012-08-16 09:42:33
> 2012-08-16 09:42:33
> 
> 
> 502cc39f-ee21-3c89-8120-670458d0d2b2
> 96231
> 502cc39d-6325-ad25-5b64-670458d0d2b2
> 2012-08-16 09:21:01
> 2012-08-16 09:21:01
> 
> 
> *
> *
> *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.*Warning* 
> (2):
>  
> SimpleXMLElement::__construct() 
> [simplexmlelement.--construct]:
>  
> Entity: line 3: parser error : Extra content at the end of the document [*
> CORE\Cake\Utility\Xml.php*, line 
> *197*]Code
>  
> Context
>
> 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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: REST, Xml::fromArray() and find('all')

2012-08-28 Thread Ryan Willis
I can confirm this issue. The Xml class does not play nice with the array 
structure generated by the model find method when multiple records are 
returned. Due to the time sensitive nature of my task, I opted to use JSON 
rather than debug a core utility class. That said, I would certainly love 
to hear the fix if anyone has it readily available.

Ryan

On Thursday, 23 August 2012 04:47:02 UTC-6, Alexandre Leprêtre wrote:
>
> Hi everyone,
>
> 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*
>  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* 
>  $xml = Xml::fromArray(array('orders' => $orders));
> echo $xml->asXML();
>
> I tried this with the first account and everything was fine
>
> *Ouput:*
> 
> 
> 502cc39f-5b74-4a25-9bb2-670458d0d2b2
> 96277
> 502cc39d-8640-465a-b0da-670458d0d2b2
> 2012-08-16 09:55:43
> 2012-08-16 09:55:43
> 
> 
>
> 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:*
> 
> 
> 502cc39f-66eb-59d2-2337-670458d0d2b2
> 96255
> 502cc39d-6325-ad25-5b64-670458d0d2b2
> 2012-08-16 09:42:33
> 2012-08-16 09:42:33
> 
> 
> 502cc39f-ee21-3c89-8120-670458d0d2b2
> 96231
> 502cc39d-6325-ad25-5b64-670458d0d2b2
> 2012-08-16 09:21:01
> 2012-08-16 09:21:01
> 
> 
> *
> *
> *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.*Warning* 
> (2):
>  
> SimpleXMLElement::__construct() 
> [simplexmlelement.--construct]:
>  
> Entity: line 3: parser error : Extra content at the end of the document [*
> CORE\Cake\Utility\Xml.php*, line 
> *197*]Code
>  
> Context
>
> 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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




REST, Xml::fromArray() and find('all')

2012-08-23 Thread Alexandre Leprêtre
Hi everyone,

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*
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* 
 $orders));
echo $xml->asXML();

I tried this with the first account and everything was fine

*Ouput:*


502cc39f-5b74-4a25-9bb2-670458d0d2b2
96277
502cc39d-8640-465a-b0da-670458d0d2b2
2012-08-16 09:55:43
2012-08-16 09:55:43



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:*


502cc39f-66eb-59d2-2337-670458d0d2b2
96255
502cc39d-6325-ad25-5b64-670458d0d2b2
2012-08-16 09:42:33
2012-08-16 09:42:33


502cc39f-ee21-3c89-8120-670458d0d2b2
96231
502cc39d-6325-ad25-5b64-670458d0d2b2
2012-08-16 09:21:01
2012-08-16 09:21:01


*
*
*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.*Warning* 
(2):
 
SimpleXMLElement::__construct() 
[simplexmlelement.--construct]:
 
Entity: line 3: parser error : Extra content at the end of the document [*
CORE\Cake\Utility\Xml.php*, line 
*197*]Code
 
Context

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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.