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

obtain objects of a class


Reply


2 Posts   733 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, 1799 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);