Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

1155 Posts in 324 Topics by 274 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Unsetting DataObjects when iterating through a DataObjectSet

Page: 1
Go to End
Author Topic: Unsetting DataObjects when iterating through a DataObjectSet 414 Views
  • Smurkas
    avatar
    Community Member
    88 posts

    Unsetting DataObjects when iterating through a DataObjectSet Link to this post

    Hello.

    I have been following the tutorials and I am using one of the functions listed to get the latest news items on different pages.
    However, I only want to show the news items that the user has access to. Figuring out if the current item could be viewed was really easy but getting rid of the offending news items proved to be harder.

    I ended up creating a new DataObjectSet and putting the DataObjects that the user can view in the new set and then returning that, but I am thinking that there must be an easy way to unset a DataObject during a foreach loop but I just can't find it.

    Also is there an easy way to restrict a DataObject::get() to only get the records that the user is allowed to view so I don't have to filter after the fact?

    Kindly, Marcus.

  • Willr
    avatar
    Moderator
    2744 posts

    Re: Unsetting DataObjects when iterating through a DataObjectSet Link to this post

    DataObject::get() to only get the records that the user

    Not well, I always just do a foreach loop after it if($object->can('View')) ...;

    To unset it can't you just call remove? I don't think PHP will complain about concurrency errors with the following

    foreach($pages as $page) {
    $pages->remove($page);
    }

    414 Views
Page: 1
Go to Top

Currently Online: There is nobody online.

Welcome to our latest member: Newclear

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.