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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Need help to use more than one DataObjectManager within a single FieldSet return?in


Go to End


1392 Views

Avatar
DaveTh

Community Member, 14 Posts

28 October 2010 at 12:58am

I am learning how to use the DataObjectManager module.

The followings are the 3 DataObjects (Data2,Data3,Data4) nested to one parent DataObject (Data1).
From the parent Data1 popup, I can only have access to one nested Dataobject e.g. Data2. I need suggestion to what I need to do to allow access to all the nested children dataobjects (Data2,Data3, and Data4). Thank you


//Nested DataObjects
class Data2 extends DataObject {
    static $db = array(
        'Title'=>'Text',
        'Description'=>'Text'
    );
}
//Nested DataObjects
class Data3 extends DataObject {
    static $db = array(
        'Title'=>'Text',
        'Description'=>'Text'
    );
}
//Nested DataObjects
class Data4 extends DataObject {
    static $db = array(
        'Title'=>'Text',
        'Description'=>'Text'
    );
}


class Data1 extends DataObject {

    static $db = array(
        'Name' => 'Text',
    );

    static $has_many = array(
        'Data2List' => 'Data2 ',
        'Data3List' => 'Data3 ',
        'Data4List' => 'Data4 '
    );

    static $has_one = array(
        'Data1List' => 'Data1Holder'
    );

  function getCMSFields() {

        $fieldListSymptomList = array();

        return new FieldSet(
                new TextField('Name', 'Data1 Name'),
                new DataObjectManager($this, $Data2List, $Data2),
                new DataObjectManager($this, $Data3List, $Data3),
                new DataObjectManager($this, $Data4List, $Data4)
        );
    }

}


class Data1Holder extends Page {

//put your code here
    static $db = array(
    );
    static $has_many = array(
        'Data1List' => 'Data1'
    );
    static $allowed_children = array('Data1');

    public function getCMSFields() {

        $f = parent::getCMSFields();
        $manager = new DataObjectManager(
                        $this, // Controller
                        'Data1List', // Source name
                        'Data1', // Source class
                        array('Name' => 'Data1 Name'), // Headings
                        'getCMSFields_forPopup' // Detail fields function or FieldSet
                // Filter clause
                // Sort clause
                // Join clause
        );


        $f->addFieldToTab("Root.Content.Data1", $manager);

        return $f;
    }
}

This work, but when I uncommend all 3 DataObjectManager, I get an error during popup for Data1.


       //class Data1
        return new FieldSet(
                new TextField('Name', 'Data1 Name'),
                //new DataObjectManager($this, $Data2List, $Data2),
                //new DataObjectManager($this, $Data3List, $Data3),
                new DataObjectManager($this, $Data4List, $Data4)
        );