Jump to:

23358 Posts in 17875 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Iterating through classes with an extension

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: 239 Views
  • g4b0
    Avatar
    Community Member
    6 Posts

    Iterating through classes with an extension Link to this post

    How can I get a list of all classes extended by a DataExtension?

    g4b0

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Iterating through classes with an extension Link to this post

    Going that way might be tricky Object::has_extension($class, $extension) would be one piece of API that would help, though you would need to get a list of classes though. ClassInfo::subclassesFor('DataObject') will give you an array of dataobject classes so you could use both

    foreach(ClassInfo::subclassesFor('DataObject') as $className) {
    if(Object::has_extension($className, 'YourExtension')) {
    // class has extension
    }
    }

  • g4b0
    Avatar
    Community Member
    6 Posts

    Re: Iterating through classes with an extension Link to this post

    I solved with:

    foreach(ClassInfo::subclassesFor('DataObject') as $class ) {
    if (singleton($class)->hasExtension("ZkTwitterExtension")) {

    Do you think your version is more performat, or they're the same?

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