Hi all. I have a client in need of a Testimonials section of their site and decided to have a gander at the sample code at the top of http://doc.silverstripe.com/doku.php?id=modules:dataobjectmanager.
I had a few issues, and am having continuing issues still. It's strange. At first it seemed to work, but no more.
First, here's the exact code I am using:
TestimonialPage.php
class TestimonialPage extends Page {
public static $db = array(
);
public static $has_one = array(
);
static $has_many = array(
'Testimonials' => 'Testimonial'
);
static $icon = "mysite/images/treeicons/testimonials";
static $defaults = array(
'ShowInMenus' => false
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Testimonials", new DataObjectManager(
$this,
'Testimonials',
'Testimonial',
array('Date' => 'Date','Author'=>'Author','Quote' => 'Quote'),
'getCMSFields_forPopup'
));
return $fields;
}
}
Testimonial.php
class Testimonial extends DataObject
{
static $db = array (
'Date' => 'Date',
'Author' => 'Text',
'Quote' => 'HTMLText'
);
static $has_one = array (
'TestimonialPage' => 'TestimonialPage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new CalendarDateField('Date'),
new TextField('Author'),
new TextareaField('Quote')
);
}
}
Problem 1: At first this all worked. But when I tried to get one Testimonial in the template, I had the errors as seen in this thread: http://www.silverstripe.org/data-model-questions/show/265300#post265300.
Problem 2: Following the above, I completely rewrote both classes just using my noodle and old code (that I know works) as a guide. After doing this, trying to load an existing TestimonialPage in the CMS shows a blank page on the right. So I refresh, entire CMS crashes without error. I managed to isolate the location of this problem to the $fields->addFieldToTab("Root.Content.Testimonials", new DataObjectManager( block in TestimonialPage.php. If I comment this out, no problem, but of course, the table and DataObjectManager are missing.
Something must be wrong with my code, as I am using DataObjectManager for the image gallery without issue.
Can someone check my code and let me know what I've bollixed please? I've gone over it such a simple peice so many times now.
Cheers
Aaron