5121 Posts in 1527 Topics by 1119 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1116 Views |
-
CTF Source filter

15 January 2009 at 4:30am Last edited: 15 January 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 -
Re: CTF Source filter

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.
| 1116 Views | ||
|
Page:
1
|
Go to Top |

