Hi Folks,
So I can't get any of the previously suggested solutions to work.
Solution #1 (PatJnr) , I get no image, no code in template.
Solution #2 (Uncle Cheese) gives me the following error: Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'Testimonial'
Solution #3(Pigeon) I get a random number link (e.g., "#1") displaying with the following extra code inserted in the template:
<ul id="Menu1"><li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">#1</a></li></ul>
Here is my code:
mysite/code/Testimonial.php
<?php
class Testimonial extends DataObject
{
static $db = array (
'Caption' => 'Varchar(50)'
);
static $has_one = array (
'TestimonialPage' => 'TestimonialPage',
'TestimonialImage' => 'Image'
);
public function getDOMThumbnail()
{
return $this->TestimonialImage()->CroppedImage(50,50);
}
function getCMSFields()
{
return new FieldSet(
new ImageField('TestimonialImage'),
new TextField('Caption','Caption')
);
}
}
?>
********************
mysite/code/TestimonialPage.php
<?php
class TestimonialPage extends Page {
static $has_many = array (
'Testimonials' => 'Testimonial'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this,
'Testimonials',// Source name
'Testimonial',// Source class
'TestimonialImage',// File name on DataObject
array('Caption' => 'Caption'),
'getCMSFields'
);
$manager->setAllowedFileTypes(array('jpg'));
$manager->setBrowseButtonText("Upload (JPG only)");
$fields->addFieldToTab("Root.Content.Testimonials",$manager);
return $fields;
}
} /* end SiteTree */
class TestimonialPage_Controller extends Page_Controller {
/* example 2 */
function RandomTestimonial (){
$ImageURL = DataObject::get_one('Testimonial', '',true,'Rand()');
return $ImageURL; }
}
/* example 3 */
function getRandomObject() {
if ($do = DataObject::get('Testimonial')) {
return $do->getRange(rand(0,$do->Count() - 1),1);
}
}
} /* end Controller */
?>
************************
templates/layout/Testimonial.ss (example 2)
<div id="Mainbody">$RandomTestimonial</div>
templates/layout/Testimonial.ss (example 3)
<div id="Mainbody">$getRandomObject</div>
I wasn't sure if I was to give the object source name or class in the DataObject::get('Testimonial')) part. I tried doing both with no luck.
Anymore help would be greatly appreciated.
Thanks,
Sam