Leah Collins
Leah Collins

Reputation: 637

Cakephp 2.0 using xml in plugin

I am trying to migrate the plugin from cakephp 1.3 to 2.x.

Original code

        App::import('Core', 'Xml');
        $Xml = new Xml($response);
        $response = $Xml->toArray(false); // Send false to get separate elements
        $Xml->__destruct();
        $Xml = null;

I think in cakephp 2.x app::import('Core', 'Xml'); world become App::import('Utility', 'Xml'); Should i use Xml::toArray(Xml::build($response));. Then I am stuck. I appreciate any help.

Upvotes: 1

Views: 1039

Answers (1)

mark
mark

Reputation: 21743

No it would become

App::uses('Xml', 'Utility');

as App::import() is now only for non-class files and vendor files.

Then you can use it just like this:

$xml = Xml::build($filenameOrXmlContent);
$array = Xml::toArray($xml);

see http://book.cakephp.org/2.0/en/core-utility-libraries/xml.html

Upvotes: 3

Related Questions