Hi Matt,

I saw your post from a few days ago.  I copied my code from the
tutorial, but it did not work at all.  I can only get XML::build() to
work with a one element array.  Creating an array such as
array("Employees"=>$this->Employee->find('all')) was also giving me an
error, so I've devised the following workaround for now.

EmployeesController:

function index(){
  $this->set('employees', $this->paginate('Employee'));
  $this->set('name', $this->name);
}

/app/View/Employees/xml/index.ctp:
<?php

  echo "<$name>";
  foreach($employees as $e){
    $xml = Xml::build($e);
    $children = $xml->children();
    $key = key($e);
    echo "<$key>";

    foreach($children as $ckey=>$cvalue){
      echo "<$ckey>$cvalue</$ckey>";
    }
    echo "</$key>";
  }
  echo "</$name>";
?>


If anyone knows of a better workout around or how to get things
working with the CakePHP Xml Utility, I would be very interested.


On Nov 14, 2:32 pm, Matt Kaufman <[email protected]> wrote:
> Me too.  It doesn't work the way that it does in 1.3.
>
> It used to work but does not in Cake 2.  Look at my mailing list posts from a 
> few days ago on this topic.
>
> Matt Kaufman
> Http://mkfmn.com
>
> Sent from my iPhone
>
> On Nov 14, 2011, at 10:58 AM, Will <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I am trying to activate the REST functionality in CakePHP 2.0 for one
> > of my models called "Employee".  In my controller, I have:
>
> > function index(){
> >    $this->set('employees', $this->paginate('Employee'));
> > }
>
> > In my view for the XML (/app/View/Employees/xml/index.ctp), I have:
>
> > <employees>
> >    <?php
> >    $xml = Xml::build($employees);
> >    echo $xml->saveXML();
> >    ?>
> > </employees>
>
> > I keep getting an "Invalid input.  Error: An Internal Error Has
> > Occurred." message.  I looked through the code a bit and found that
> > the Xml class appears to be expected an array with 1 and only one
> > element and an alphanumeric key.  This makes me think that the example
> > in the book (http://book.cakephp.org/2.0/en/development/rest.html?
> > highlight=rest), which describes passing the result of $this->Recipe-
> >> find('all') to Xml::build(), is wrong because $this->Recipe-
> >> find('all') will return an array with numeric indices and multiple
> > elements.
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group 
> > athttp://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to