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.

Data Model Questions /

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

Band Listing Has_Many!


Go to End


1099 Views

Avatar
Jaymonkey

Community Member, 10 Posts

13 February 2014 at 4:59am

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?