Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Band Listing Has_Many!

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

Page: 1
Go to End
Author Topic: 225 Views
  • Jaymonkey
    Avatar
    Community Member
    10 Posts

    Band Listing Has_Many! Link to this post

    Hi,

    I am trying to create a page with three tabs which read "Friday", "Saturday" and "Sunday". Within these tabs will be a sortable gridfield with a list of bands that are playing on those respective dates.

    My first effort at this ended up showing the same list of bands on each tab, but apart from that all was okay! I am guessing my problem is something to do with relationships.

    I am now trying this:

    //////Stage.php//////
    <?php
    class Stage extends DataObject {

    private static $has_many = array (
    'Bands' => 'Band'
    );

    }

    ?>

    //////Band.php///////
    <?php
    class Band extends DataObject {

    private static $db = array (
    'Name' => 'Text',
    'Link' => 'SiteTree'
    );

    private static $has_one = array (
    'Stage' => 'Stage'
    );

    public function getCMSFields() {

    $fields = new FieldList (
    new TextField('Name'),
    new TreeDropdownField ('Link', 'Link', 'SiteTree')
    );

    return $fields;
    }
    }

    ?>

    //////LineupPage.php/////////
    <?php
    class LineupPage extends Page{

    public function init() {
    parent::init();
    }

    public static $db = array (
    'FridayHeadline' => 'Text',
    'FridayHeadlineImage' => 'Image',
    'FridayHeadlineLink' => 'SiteTree',
    'SaturdayHeadlineBand' => 'Text',
    'SaturdayHeadlineImage' => 'Image',
    'SaturdayHeadlineLink' => 'SiteTree',
    'SundayHeadline' => 'Text',
    'SundayHeadlineImage' => 'Image',
    'SundayHeadlineLink' => 'SiteTree'
    );

    public static $has_one = array (
    'FridayBands' => 'Stage',
    'SaturdayBands' => 'Stage',
    'SundayBands' => 'Stage'
    );

    public function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->removeFieldFromTab("Root.Main", "Content");

    ///Some code here to pull each band through it's respective stage, into individual tabs on grid fields!
    }

    }

    ?>

    Can anybody give me some pointers please?

    225 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.