Noob q, sorry. I’m working my way up to doing proper loops, and I’m playing around with various case studies and tutorials. I’ve created a custom table, schema, model etc, and I’m using getCollection and foreach to list each row within that collection (no error checking or whatever, I know there’s data there).
When I output the data, it always seems to be prefixed with the word ’Array’ - which I assume means I’m doing something wrong. As far as I can tell I’ve only changed the variable names and copied someone’s example on the forum.
Code:
$base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/ias_newsletter/';
$modx->addPackage('ias_newsletter',$base_path.'model/');
$subscriber = $modx->newObject('ias_newsletter');
$subscribers = $modx->getCollection('ias_newsletter',array('active'=>"1"));
echo 'Total active: '.count($subscribers);
foreach ($subscribers as $z)
{
$subscribers .= $z->get('name')."<br />";
$subscribers .= $z->get('email')."<br />";
$subscribers .= $z->get('active')."<br />";
}
return $subscribers;
1. So why’s it spitting out ’Array’ before the data I want?
2. I’m a bit lost as to why the $subscriber object is required, or is it? Nothing seems to happen to it....