Jump to:

23355 Posts in 17744 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » obtain objects of a class

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: 676 Views
  • Paco728
    Avatar
    Community Member
    28 Posts

    obtain objects of a class Link to this post

    Hi all.

    Would be like to obtain the objects of a particular class only and not all are of the same class

    is for use as dropdownfield options.

    I'm using DataObject:: get ('class') and this works but selects all classes and I just need this particular

    Attached Files
  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: obtain objects of a class Link to this post

    something like...

    $dos = DataObject::get('class');
    foreach ($dos as $do) {
    if (!in_array($do->ClassName,array('class1','class2'))) {
    $dos->remove($do);
    }
    }
    $map = $dos ? $dos->toDropdownMap() : array();
    $df = new DropdownField($strFieldName,$strLabel,$map);

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