Jump to:

23483 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » multiple instanes of class in page

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

Page: 1
Go to End
Author Topic: 654 Views
  • wainui
    Avatar
    Community Member
    56 Posts

    multiple instanes of class in page Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: multiple instanes of class in page Link to this post

    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;
    }
    }

    654 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.