Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

DataOject - testimonial


Reply


4 Posts   1085 Views

Avatar
Monty

Community Member, 19 Posts

9 August 2010 at 7:59am

Edited: 09/08/2010 8:04am

Hi guys,

I am trying to create a function that displays random projects (image and text) on my About page if there is a testimonial assigned (filled out in CMS) to that project. I have the correct code for other similar functions i.e pulling the project to homepage if item is checked (in CMS) so I`m nearly there with this one.

In Page.php

public function SelectedAbout() {
return DataObject::get("PortfolioPage", "FILTER REQUIRED HERE", "RAND()", null, "");
}

In PortfolioPage.php

class PortfolioPage extends Page {
static $db = array(
'Url' => 'Text',
'ProjectInfo' => 'HTMLText',
'DisplayHomepage' => 'Boolean',
'Testimonial' => 'HTMLText'
...

Your help is appreciated.

Cheers,
Dave

Avatar
NickJacobs

Community Member, 144 Posts

9 August 2010 at 8:59am

Edited: 09/08/2010 9:04am

Hi Dave, off the top of my head, this should do what you need:

return DataObject::get("PortfolioPage", "Testimonial <>''", "RAND()", null, "");

Avatar
Monty

Community Member, 19 Posts

9 August 2010 at 11:02am

Thanks for that Nick. Your speedy response is appreciated. Look forward to getting my portfolio site up soon.

Cheers,
Dave

Avatar
Monty

Community Member, 19 Posts

9 August 2010 at 7:49pm

Edited: 09/08/2010 7:56pm

This worked a treat with a very slight modification to pull only one random project with a testimonial from all the projects that had a testimonial associated with it only.

So for the good of all...

Page.php - Adding the 1 limited the set to one row (in this case random).

public function SelectedAbout() {
return DataObject::get("PortfolioPage", "Testimonial <>''", "RAND()", null, "1");
}

AboutPage.ss

...

<p>$Testimonial.FirstSentence</p>
...