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, Ed, biapar, Willr, Ingo, swaiba

trying to get the latest images out of an ImageObject

Go to End

5 Posts   1036 Views


Community Member, 72 Posts

1 February 2012 at 10:44pm

Edited: 01/02/2012 10:52pm

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. Website


Forum Moderator, 4102 Posts

2 February 2012 at 4:44am

How does GalleryPage relate to GalleryImageObject?

SilverStripe tips, tutorials, screencasts and more:


Community Member, 72 Posts

2 February 2012 at 5:08am

Edited: 02/02/2012 7:54am

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); 


Community Member, 72 Posts

3 February 2012 at 6:21am



Community Member, 72 Posts

6 February 2012 at 2:44am

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?