Hi guys, me again! Looking for a bit of help as I've tied myself in knots here!
I'm looking to create a new tab in the CMS with a ComplexTableField, where the user can add Testimonials that relate to each specific page. (This will be for ANY page on the site that uses or derives from "Page.php", but each testimonial will be unique to only the page it was created on.)
Initially I had set it up so that there was only one testimonial per page; on page.php I used the static $db array to create a few fields (quote, name, company)
However, we now want to have it so that the user can add as many Testimonials as they like. I decided to do this using the ComplexTableField.
First of all I created the object, Testimonial.php:
<?php
class Testimonial extends DataObject {
static $db = array(
'Quote' => 'Text',
'Name' => 'Varchar(255)',
'Company' => 'Varchar(255)',
'Status' => "Enum('Active,Inactive', 'Active')",
);
static $singular_name = 'Testimonial';
static $plural_name = 'Testimonials';
static $has_one = array(
);
static $default_sort = "Name ASC";
}
?>
Then in page.php I put in the following code:
...
public static $has_one = array(
'Testimonials' => 'Testimonial',
);
function getCMSFields() {
$fields = parent::getCMSFields();
$TestimonialsTable = new ComplexTableField($this, 'Testimonials', 'Testimonial', array('Name'=> 'Name'));
$fields->addFieldToTab("Root.Content.Testimonial", new HeaderField( Client Testimonials:', '3', true ));
$fields->addFieldToTab('Root.Content.Testimonial', $TestimonialsTable);
return $fields;
}
...
So this *seemed* to work, but then I realised that if I add a testimonial on one page, it appears on ALL pages that derive from page.php!!!
I guess I've got the relationship thing wrong somewhere?
I tried adding the following code to Testimonial.php, but it didn't have the desired effect - it just created a dropdown box with all the site pages in the modal dialog! (So I've removed it again)
static $has_one = array(
'Page' => 'Page',
);
Basically, I need to know how to say "when I create a testimonial on Page-A it only appears on Page-A"
All help is appreciated, as always!!! I'm reading through my silverstripe book just now to try and figure it out, but my brain hurts!!!
Thanks,
Linsey (",)