Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

trying to get the latest images out of an ImageObject


5 Posts   635 Views


1 February 2012 at 10:44pm (Last edited: 1 February 2012 10:52pm), Community Member, 72 Posts

Hi @ all,

I'm trying to create my own image gallery. The galleries preview at the holder, should contain the last 4 images of this gallery.
The way i tried it doesn't work. I hope someone could help me.

The relations between the single pages and objects
GalleryHolder.php -> GalleryPage.php -> GalleryImagesObject.php -> Image Image Image ...

The GalleryHolder.php has this two function to sort the galleries and to get the latest 4 images of each gallery

   public function getGalleries() {
      return DataObject::get('GalleryPage', "ParentID = '$this->ID'", 'Date DESC');
   function LatestGalleryImages($num=4) {
   $galleryimage = DataObject::get_one("GalleryHolder");
   return ($galleryimage) ? DataObject::get("GalleryPage", "ParentID = $galleryimage->ID", "Date DESC", "", $num) : false;

that's the GalleryImagesObject.php

class GalleryImagesObject extends DataObject {

   public static $db = array(
      'Title' => 'Text',
      'Description' => 'Text'

   public static $has_one = array(
      'GalleryImage' => 'Image',
      'GalleryPage' => 'GalleryPage'

   public function getCMSFields_forPopup() {

return new FieldSet(
   new TextField('Title', 'Titel des Bildes'),
   new TextAreaField('Description', 'Beschreibung des Bildes'),
   new ImageField('GalleryImage', 'Bild(er) hochladen')



and my looks like this.

<% control getGalleries %>
   <% control GalleryImagesObject %>
   <% end_control %>
   <a href="$Link" title="Die Gallerie $Title anzeigen">$Title</a>
<% end_control %>


Where's the mistake(s) i made? I can see the link but not the images :(
Thx for your Help


P.s. [url=]Website[/url]


2 February 2012 at 4:44am 4085 Posts

How does GalleryPage relate to GalleryImageObject?

SilverStripe tips, tutorials, screencasts and more:


2 February 2012 at 5:08am (Last edited: 2 February 2012 7:54am), Community Member, 72 Posts

Sry, i think that was wrong in my first post. I'm not able to describe the relations good in english.

Thats the GalleryPage.php I hope it will help

class GalleryPage extends Page {
   static $allowed_children = 'none';
   static $default_parrent = 'GalleryHolder';
   static $can_be_root = false;

   public static $db = array(
      'Date' => 'Date',
      'Description' => 'HTMLText',
      //'ThumbnailSize' => 'Text',
   public static $has_many = array(
      'GalleryImages' => 'GalleryImagesObject'

   function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->removeFieldFromTab('Root.Content.Main', 'Content');
      $fields->addFieldToTab('Root.Content.Main', $date = new DateField('Date', 'Datum der Aufnahmen'));
      $date->setConfig('showcalendar', true);   
      $fields->addFieldToTab('Root.Content.Main', new SimpleTinyMCEField('Description','Beschreibung der Gallerie'));
      //$fields->addFieldToTab('Root.Content.Main', new TextField('ThumbnailSize','Größe der Thumbnails (in px / muss ausgefüllt sein)'));
      $fields->addFieldToTab('Root.Content.Main', $GalleryImages = new ImageDataObjectManager($this, 'GalleryImages', 'GalleryImagesObject', 'GalleryImage', array('Title' => 'Titel des Bildes', 'Description' => 'Beschreibung des Bildes'), 'getCMSFields_forPopup'));
      $GalleryImages->copyOnImport = false;
      //$GalleryImages->setPageSize( '999' );
      return $fields;

class GalleryPage_Controller extends Page_Controller {

   public function PrevNextPage($Mode = 'next') {
      if($Mode == 'next'){
         $Where = "ParentID = ($this->ParentID) AND Sort > ($this->Sort)";
         $Sort = "Sort ASC";
      elseif($Mode == 'prev'){
         $Where = "ParentID = ($this->ParentID) AND Sort < ($this->Sort)";
      $Sort = "Sort DESC";
      return false;
      return DataObject::get("SiteTree", $Where, $Sort, null, 1);


3 February 2012 at 6:21am Community Member, 72 Posts



6 February 2012 at 2:44am Community Member, 72 Posts

Hmm is it possible to get the latest Entry out of an DataObject with the Mysql Field "Created" ? If got absolutly no knowlege about sql but i think it should be possible?!

Perhapse this is one way?