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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

obtain objects of a class


Go to End


2 Posts   1325 Views

Avatar
Paco728

Community Member, 28 Posts

13 August 2011 at 6:06pm

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
Avatar
swaiba

Forum Moderator, 1899 Posts

17 August 2011 at 10:38pm

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);