CMBase.php - getting data back in XML - here's how

Hi Guys

The default return type for CMBase.php is an array. I noticed an issue with the contents of this array as it was translated by the CMBase object from XML to array, which the CM guys are looking into.

Anyways....I much prefer to work with the XML myself in my PHP code, and if you do too, you can make a couple of quick changes to CMBase.php to let you do this:

1. In function make_call, give $res and XML option:

// JOC added xml method to get round xml2array problem with CustomFields
    else if ($this->method = "xml") {
        return $res;                

This code goes inside the 'if ($res)' block at the bottom of the function make_call.

2. In your PHP scripts, call your CMBase constructor with a last parameter for method of 'xml'

Now things come back in the API's native XML format.

The real benefit of this is that you can then use PHP's SimpleXMLElement object to use API objects really easily.
For starters, I created a proper CMList and Subscriber object that allows access to all subscriber properties using 

$mysubscriber->name_of_my_custom_field syntax


They also let you iterate through lists, and count list numbers by simple access to the list object.

If anyone's interested in this I'll post the code.

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free