7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [SOLVED] Testimonials Tutorial Code
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 2084 Views |
-
[SOLVED] Testimonials Tutorial Code

24 July 2009 at 10:26am Last edited: 24 July 2009 11:31am
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 -
Re: [SOLVED] Testimonials Tutorial Code

24 July 2009 at 11:30am
Cancel that. I completely rewrote the classes for a third time and tested in a sandbox. All working now so there must have been a minor error in my original code.
FYI, here is the working code for the Testimonials that I am using:
TestimonialPage.php
class TestimonialPage extends Page {
static $db = array(
);
static $has_one = array(
);static $has_many = array(
'Testimonials' => 'Testimonial'
);static $icon = "mysite/images/treeicons/testimonials";
static $defaults = array(
'ShowInMenus' => false
);
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'
);function getCMSFields_forPopup() {
return new FieldSet(
new CalendarDateField('Date'),
new TextField('Author'),
new TextareaField('Quote')
);
}
}Nothing else needed to change, and both issues are fine now.
Aaron
| 2084 Views | ||
|
Page:
1
|
Go to Top |

