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:

General Questions /

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

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

Cannot Reference Banner Image more than Once


Go to End


5 Posts   1396 Views

Avatar
tigger

Community Member, 3 Posts

3 September 2010 at 4:36am

*** 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

Community Member, 135 Posts

4 September 2010 at 1:30am

Edited: 04/09/2010 1:30am

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

Avatar
tigger

Community Member, 3 Posts

4 September 2010 at 2:16am

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

Community Member, 135 Posts

4 September 2010 at 2:39am

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

Community Member, 3 Posts

4 September 2010 at 2:42am

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