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.
Cheers
Justin

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098