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.

Data Model Questions /

Band Listing Has_Many!


Reply


355 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?