ZenDB and images

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 27   (RSS)

Hi Jeff, 

Using getRecords() might be the easiest right now, we're working on other options for ZenDB in future.

Or here's a workaround using a CMSB function that gets you an array:

$rows = DB::select('articles')->toArray();
addUploadsToRecords($rows, $baseTable);
showme($rows);

Or converting it back to a SmartArray and using that.

$rows = DB::select('articles')->toArray();
addUploadsToRecords($rows, $baseTable);
$rows = SmartArray::new($rows);

showme($rows);

foreach ($rows as $record) {
    echo "<h1>$record->name</h1>\n";
    foreach ($record->uploads as $upload) {
        echo "<img src='$upload->urlPath'><br>\n";
    }
}

Hope one of those solutions works for you.  

Cheers!

Dave Edis - Senior Developer
interactivetools.com

Hi Jeff, 

We've now got this built into the latest CMSB beta.  Here's what you can do in the beta instead of the above code: 

$records = DB::select('articles');
foreach ($records as $record) {
    echo "<h1>$record->name</h1>\n";  
    foreach ($record->load('uploads') as $upload) {
        echo "<img src='$upload->urlPath'><br>\n";
    }
}

If you get a chance to try it out let us know any feedback.  Thanks!

Dave Edis - Senior Developer
interactivetools.com