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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Cannot Reference Banner Image more than Once


Reply

5 Posts   1029 Views

Avatar
tigger

3 September 2010 at 4:36am Community Member, 3 Posts

*** newbie/noob question (sorry) ***

I have extended SiteTree in my Page.php to provide support for banner images on pages within my site - and this works as intended, for example:

class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
'BannerImage' => 'Page_BannerImage',
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields ->addFieldsToTab(
'Root.Content.Banner',
new ImageField('BannerImage', 'Banner')
);

return $fields;

}

function getBannerImageRecursive() {
$page = $this;
$banner = $this->BannerImage();
while(!$banner->ID && $page->ParentID !=0) {
$page = $page->Parent();
$banner = $page->BannerImage();
}

return $banner;

}

The obstacle I have encountered is that once an image is selected from the File Store and attached to a page, that image is no longer referenced in the File Store list and cannot (apparently) be used as an attachment for another page. Yes, I know that I can attach an image from my file system (workaround?) yet, I am looking for a method that continues to enumerate the files/images on the File Store list.

Any ideas???

Avatar
dendeffe

4 September 2010 at 1:30am (Last edited: 4 September 2010 1:30am), Community Member, 135 Posts

I'm also having this problem a lot. I tend to use the Image DataObjectManager instead.

Avatar
tigger

4 September 2010 at 2:16am Community Member, 3 Posts

dendeffe - Thanks for the tip on an alternative method! Now, (and since I am a novice here) would you explain how I might go about implementing the Image DataObjectManager class? Or at least point me to some explanatory documentation? - thanks in advance.

Avatar
dendeffe

4 September 2010 at 2:39am Community Member, 135 Posts

It’s part of the Data Object Manager extension: http://www.silverstripe.org/dataobjectmanager-module/

which has pretty good documentation.

You can also check out UncleCheese’s (who develops it) screencast: http://www.leftandmain.com/silverstripe-screencasts/2010/08/23/a-quick-look-imagegallery-module/

Avatar
tigger

4 September 2010 at 2:42am Community Member, 3 Posts

Thank you! I will evaluate this alternative and let you (and everyone in the forum) know how it turns out!