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.

Customising the CMS /

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

CTF Source filter


Go to End


2 Posts   2071 Views

Avatar
ChrisBryer

Community Member, 95 Posts

15 January 2009 at 4:30am

Edited: 15/01/2009 4:31am

Hi everyone,
I know i can show dataobjects in a CTF that are assigned to one page by using the source filter, however i want the dataobject usable by a few different class files, and I'm not sure how to set up the dataobject's has_one relationship. here's what I have:

(code is in ProductCategory.php, ProductPage.php, and a few others that all extend Page)
$downloadfield = new ComplexTableField(
	$this,
	'RelatedDownloads',
	'DownloadLink',
	array(
		'LinkName' => 'Name'
	),
	'getCMSFields', 
	"DownloadLink.DownloadlinkToPageID = {$this->ID}"
);
$downloadfield->setParentClass('ProductCategory');
$downloadfield->relationAutoSetting = true;

class DownloadLink extends DataObject {
	static $db = array(
		'LinkName' => 'Text'
	);
	static $has_one = array(
		'Document' => 'File',
		'DownloadLinkToPage' => 'Page'  // (THIS WORKS AS 'ProductCategory'  or 'ProductPage')
	);
	function getCMSFields() {
		$fields = new FieldSet();
		$fields -> push(new TextField("LinkName", "Name"));
		$fields -> push(new ImageField('Document'));
		return $fields;
	}
}

I'm not sure how to set up the has_one relationship on the DownloadLink class.. I was hoping that the superclass of the ProductCategory and ProductPage classes (Page) would return records to the calling classes but nothing shows up in the CTF. data is created in the database, and the DownloadLink Dataobjects do have the correct 'DownloadLinkToPageID', and everything works if i change Page to ProductPage in the has_one relationship.

any thoughts?
thanks,
-Chris

Avatar
ChrisBryer

Community Member, 95 Posts

15 January 2009 at 8:21am

I figured it out. Because DownloadLink was being used by multiple classes, and each calling class had the same tables, i made a superclass with the tables, and subclassed from there.