I’m trying to get the Mailchimp datasource from Springest working, and I’m having issues. I had to modify some code to get rid of CakePHP errors. Now it happens without errors, but there is no actual API request made to Mailchimp.
The Model, Datasource and Controller function code is exactly the same as in the download from Springest.
The code in my database.php file is:
public $mailchimp = array(
'datasource' => 'MailchimpSubscriber',
'apiKey' => '<my mailchimp API key>',
'defaultListId' => '<my list identifier>',
'baseUrl' => 'http://us1.api.mailchimp.com/1.2/'
);
I am running CakePHP 2.1.0 on XAMPP on my Macbook Pro.
Anybody got any clues?
==UPDATE==
I’ve uploaded a stripped-out controller here: https://gist.github.com/3011716
Here is the code for my view:
<h2>Subscribe to Mailchimp</h2>
<?php
echo $this->Form->create('People', array('action' => 'subscribe'));
echo $this->Form->input('id');
echo $this->Form->input('emailaddress');
echo $this->Form->input('FNAME');
echo $this->Form->input('LNAME');
echo $this->Form->input('GENDER');
echo $this->Form->end('Submit');
?>
Thanks for trying out our Mailchimp Datasource. One of the problems might be that is was written for CakePHP 1.2+ and that a lot of stuff has changed in CakePHP since the 2.0 release.
Note that we’re still using Cake 1.3 with the datasource and experience no errors whatsoever.
Did you check out the migration guide from CakePHP 1.3 to 2.0? Right at the bottom there’s some mentioning of changes done to DataSources, so the error might be related to that.
We’ll try to take it for a spin in Cake 2.0 and see what goes wrong, but in the mean time, this might be helpful.
==UPDATE==
Yup, it was CakePHP 2.0 that was not compatible. I’ve ported the datasource to support CakePHP 2.0, please check the updated repository.
== SECOND UPDATE==
You’ve made one error in your view: because you’ve created the form with
$this->Form->create('People', array('action' => 'subscribe'));the data of the form will be in the$this->dataarray with keyPeoplewhereas it should have the keyMailchimpSubscriber. Because there’s no key with that name in your$this->datathe MailchimpSubscriber model will ignore the save action. You’ll need to change your submission form in such a way that the submitted data has the right model name as key.Another note: you’re now loading the
MailchimpSubscribermodel twice. The first time in the$usesarray in the controller and the second time through the$this->loadModel()method in the controller action. I would only use the latter.