Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataOject - testimonial

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1014 Views
  • Monty
    Avatar
    Community Member
    19 Posts

    DataOject - testimonial Link to this post

    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

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: DataOject - testimonial Link to this post

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

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

  • Monty
    Avatar
    Community Member
    19 Posts

    Re: DataOject - testimonial Link to this post

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

    Cheers,
    Dave

  • Monty
    Avatar
    Community Member
    19 Posts

    Re: DataOject - testimonial Link to this post

    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>
    ...

    1014 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.