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.

General Questions /

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

Multiple DataObject Problem


Go to End
Reply


10 Posts   1375 Views

Avatar
Willr

Forum Moderator, 5513 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, 123 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