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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Show images in ArticleHolder


Go to End


21 Posts   5094 Views

Avatar
frabraha

Community Member, 49 Posts

26 November 2009 at 9:33pm

No no.. this isn't in ArticlePage.ss its in ArticleHolder.ss. The function works just fine in ArticlePage.ss

Maybe I didn't explain it clear enough..:)
Well here's how it is..

I have Article 1, Article 2 and article 3, each with images and text.

In ArticleHolder.ss I'm trying to list out those 3 article's with the first image.

Image - Article 1
Image - Article 2
Image - Article 3
..and so on..

Avatar
frabraha

Community Member, 49 Posts

2 December 2009 at 10:18pm

I still can't get this thing to work..
Can't find any help with this on the forum either..

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 December 2009 at 3:44am

So the code you're using is

<% control Children %>
<% control ArticleBilder.First %> 
$Attachment 
<% end_control %>
<% end_control %>

Avatar
frabraha

Community Member, 49 Posts

3 December 2009 at 9:43pm

Here is all of the code for the images:

In ArticleHolder.ss

		   <% if GetArticleFirstImage %>
			<% control GetArticleFirstImage %>	
				<% control Attachment.First %> 
					$Attachment
				<% end_control %>
			<% end_control %>
			<% else %>
				<a href="$Link"><img src="/themes/tutorial/images/blank.jpg" /></a>
			<% end_if %>

In ArticleHolder.php

	function GetArticleFirstImage($num=1){ 
	$manager = DataObject::get_one("ArticlePage"); 
	return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder", "", $num) : false; 
	}

In ArticlePage.php

   $manager = new ImageDataObjectManager(
			$this,
			'ArticleBilder',
			'ArticleBilde',
			'Attachment',
			array(
				'Name' => 'Bildenavn',
				'Description' => 'Beskrivelse' 
			),
			'getCMSFields_forPopup_articlebilder'
	);
   $fields->addFieldToTab("Root.Content.Bilder",$manager);	

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 December 2009 at 2:35am

And your ArticleBilde class?

Avatar
frabraha

Community Member, 49 Posts

4 December 2009 at 2:41am

Forgot that one..

Here:

In ArticleBilde.php

<?php
class ArticleBilde extends DataObject
{
	static $db = array (
		'Name' => 'Text',
		'Description' => 'Text',
	);
	
	static $has_one = array (
		'Attachment' => 'File',
		'ArticlePage' => 'ArticlePage'
	);
	
	public function getCMSFields_forPopup_articlebilder()
	{
		return new FieldSet(
			new TextField('Name'),
			new TextareaField('Description'),
			new FileIFrameField('Attachment')
		);
	}
}

?>

Avatar
frabraha

Community Member, 49 Posts

9 December 2009 at 1:40am

I have tried to get this to work with a fresh install of SS and just starting from scratch, but I still can't get the images to show up in the articleHolder.ss.

I've done this before, the only different is that I used DataObjectManager to manage a simple list of urls, and used this function to output it to the template:

	function GetLinksInternal(){ 
	$LinksPage = DataObject::get_one("LinksPage"); 
	return ($LinksPage) ? DataObject::get("InternalLink", "LinksPageID = {$LinksPage->ID}") : false; 
	}

And this works perfectly anywhere on the website, but when I do the same when I use imagedataobjectmanager or the filedataobjectmanager it only shows the content added in the imagedataobjectmanager or the filedataobjectmanager when you are on the right page.

Avatar
frabraha

Community Member, 49 Posts

15 December 2009 at 11:49pm

I think I have found out why this isn't working.
Its the Get function, this part isnt right: ArticlePageID = $this->ID. When I just have ArticlePageID, all of the ArticleBilde are showing in a list. SS doesn't know what do get and doesn't output anything..

I'm not that good at programming this kind of things, so how should I do this when I have an articleholder with serveral ArticlePages with images added to them, something like this:

Articleholder -> ArticlePage1 -> ArticleBilde1,ArticleBilde2,ArticleBilde2,
-> ArticlePage2 -> ArticleBilde1,ArticleBilde2,
-> ArticlePage3 -> ArticleBilde1,ArticleBilde2,

Heres the function:

function GetArticleFirstImage(){ 
   $manager = DataObject::get_one("ArticlePage"); 
   return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder") : false; 
   }