Jump to:

23001 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Adding a value to DataObject Set

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
Go to End
Author Topic: 1486 Views
  • B-Side
    Avatar
    Community Member
    42 Posts

    Adding a value to DataObject Set Link to this post

    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,

    Y

  • Jedateach
    Avatar
    Forum Moderator
    227 Posts

    Re: Adding a value to DataObject Set Link to this post

    $exhibition->Current = true;

  • B-Side
    Avatar
    Community Member
    42 Posts

    Re: Adding a value to DataObject Set Link to this post

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

    Cheers, Y

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