So I'm using MigxDB to collect email addresses entered into a form, with a CMP to manage said email addresses.
At the moment the email addresses are added with a snippet that contains the following:
$emailAddress = $modx->getOption('email', $scriptProperties, '');
$path = MODX_CORE_PATH.'components/email_subscribers/';
$modx->addPackage('email_subscribers', $path.'model/');
$subscriber = $modx->newObject('EmailSubscriber');
$date = new DateTime;
$subscriber->set('email', $emailAddress);
$subscriber->set('createdon', $date->format('Y-m-d H:i:s'));
return $subscriber->save();
I based this code from this post on Bob's Guides:
http://bobsguides.com/custom-db-tables.html.
This works absolutely fine, but I'm just wondering is this best way to achieve this? At the moment I'm treating it like it's a regular custom DB table, but it feels like there should be a way to do this with Migx itself. I've searched around and I can't find anything and I just feel like I'm missing something.
Perhaps I'm overthinking it and I should just be happy that my code works.