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

Adding a value to DataObject Set


3 Posts   1632 Views


Community Member, 42 Posts

31 May 2010 at 10:06pm

Hi all

I've been wracking my brain over something I'm sure is very simple, but it's driving me mad! I need to iterate through a DataObjectSet to find any results that fall within a specific date range so that I can highlight a current event. I think I'm close to the result, but I just can't figure out how to add a value to my DataObjectSet to flag this result in my template.

Here's my code - any advice most welcome!


function ExhibitionSydney() {
      $now = date("Y-m-d",time());

   //   Retrieve all Exhibitions
      $exhibitions = DataObject::get('Exhibition', '','DateFrom DESC');

   //   Iterate through Exhibitions to find any that fall on the current date
         foreach($exhibitions as $exhibition){
               if ( $now >= $exhibition->DateFrom && $now <= $exhibition->DateTo )   {
            //   if the result falls within the current date, add Current=>true to the dataobjectset
      return $exhibitions;

I'm running SS 2.3.7

Thanks for any assistance in advance,



Forum Moderator, 233 Posts

31 May 2010 at 10:23pm

$exhibition->Current = true;


Community Member, 42 Posts

31 May 2010 at 10:30pm

Oh man was I overthinking that one. Thanks heaps it's done the trick.

Cheers, Y