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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Multiple DataObject Problem


Go to End


10 Posts   2171 Views

Avatar
Willr

Forum Moderator, 5523 Posts

15 July 2011 at 8:59am

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.

Avatar
ambient

Community Member, 130 Posts

16 July 2011 at 3:47am

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); 
      }

Go to Top