Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Multiple DataObject Problem

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 1226 Views
  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Multiple DataObject Problem Link to this post

    You may want to read up on switch (http://php.net/manual/en/control-structures.switch.php) you should only need 1 switch statement to do that.

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Multiple DataObject Problem Link to this post

    Hi Will,

    I took a look at that and rewrote the code the way you said this time adding the break; statement and it works great.
    Thanks for all your help. It's great to get something to finally work but even better when you know it's been done right

    function NewsList($num=5) {

    switch($this->PageColor) {
    case 'Gold':
    $color = "LstGoldPage";
    break;

    case 'Purple':
    $color = "NewsPurplePage";
    break;

    case 'Magenta':
    $color = "NewsMagentaPage";
    break;

    case 'Blue':
    $color = "NewsBluePage";
    }

    return DataObject::get($color, "", "StartDate DESC", "", $num);
    }

    1226 Views
Page: 1 2
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.