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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Gallery. Get the first Image.


Go to End


3 Posts   937 Views

Avatar
kondor

Community Member, 9 Posts

18 May 2010 at 9:06am

Edited: 18/05/2010 9:10am

Hi I Use DataObjectManager Modul

And I create a realy simple Gallery, and everything works perfect, but now i want to make some kind of Holder lets say a KatalogImageHolder.php where the children are KatalogImagePage, where I want to show only the first Image of the KatalogImagePage. And I have no Idea how can I do that stuff :) (I Know this is not so really appended from DataObjectManager Modul)

Please Help me to get it work

KatalogImageHolder.php looks like this

class KatalogImageHolder extends Page {

	static $db = array(
	);

	static $has_one = array(
	);
	
	static $allowed_children = array('KatalogImagePage');
}
….

and KatalogImagePage.php like this

class KatalogImagePage extends Page
{
	static $has_many = array (
		'KatalogImages' => 'KatalogImage'
	);
	
    // Here go, I don't know how to make it run,   
    public  function getFirstPhoto(){
			return $this->KatalogImages[0]; //that doesn't work :)
    }
 
	
...

@UncleCheese. My Post has been duplicated, please delete one of them

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 May 2010 at 9:25am

In the template:

$KatalogImages.First

In the controller:

$this->KatalogImages()->First();

Avatar
kondor

Community Member, 9 Posts

18 May 2010 at 9:38pm

Oh men, @UncleCheese :)

I knowed, I've read about this, but many , many months ago ;)

It is working now, thanks for your help