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.

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

multiple instanes of class in page


Go to End


2 Posts   1024 Views

Avatar
wainui

Community Member, 56 Posts

18 July 2010 at 10:58pm

hi,
this is a newb question but just cant get it right.

I have a simple class called resource...
And i want to use the same class for 2 items in a page.
ie: I want to use the same class for a slideshow and a scroller component in end page
I have tried has_many etc but think I am missing the point.
I always have images shared...

Since I am a hack I end up duplicating the class.

surely I can use the same class????

how to I set this up as obviously will be same table and same page but different...?

Any help appreciated :)

Avatar
martimiz

Forum Moderator, 1391 Posts

19 July 2010 at 12:28am

Edited: 19/07/2010 12:29am

Something like this maybe?

class MultiPurposeClass extends DataObject{
  ...
}

class SomePage extends Page {

  static $has_one = array (
    'Scroller' => 'MultiPurposeClass',
    'SlideShow' => 'MultiPurposeClass'
  );
}

class SomePage_Controller extends Page_Controller {
  
  function SlideShow {
    return $this->SlideShow;
  }

  function Scroller {
    return $this->Scroller;
  }
}