Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How to create an empty DropDownField ? Error in DataObjectManager.php on line 584

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1040 Views
  • lise
    Avatar
    Community Member
    47 Posts

    How to create an empty DropDownField ? Error in DataObjectManager.php on line 584 Link to this post

    I populate a DropDownField automatically from an array as :

    function getCMSFields() {

    $fields = new FieldSet( new DropdownField(
        'CountryName',
        'Choose a country',
        Dataobject::get("country")->toDropdownMap("CountryName", "CountryName")
    ), ..etc ..
    }

    This works very well when 'country' already contains data. However I get an error when at init. there
    is **no country** yet in the database.

    I understand this is because Dataobject::get() is NULL and therefore the call to toDropdownMap fails.

    So I tried to use a function which tests if 'country' is empty or not :

    function CreateCountryList() {
       $myDataSet = DataObject::get("country");
       if (!$myDataSet) return false;
          else
          return $myDataSet->toDropdownMap("CountryName", "CountryName");      
    }

    $fields = new FieldSet( new DropdownField(
        'CountryName',
        'Choose a country',
        $this->CreateCountryList()
    ),
    etc...

    But with that, I can not properly create a country for the customer with the DOM. (i.e the entry is written in the DB but the DOM
    does not display it in the table and returns the error messages :

    ERROR [Warning]: Missing argument 3 for ComplexTableField_Item::__construct(), called in /home/www/xxx.com/dataobject_manager/code/DataObjectManager.php on line 584 and defined
    IN POST /admin/getitem?ID=11&ajax=1
    Line 980 in /home/www/xxx.com/sapphire/forms/ComplexTableField.php

    I guess my CreateCountryList() is wrong so my question is ...how to create an empty DropDownField ?

    I hope this is not too confusing ...

    Thanks in advance for any tip,

    Lise

    PS. I am running SS 2.3.7 with the latest DOM ( March 23 )

  • UncleCheese
    Avatar
    4085 Posts

    Re: How to create an empty DropDownField ? Error in DataObjectManager.php on line 584 Link to this post

    If you're running SS 2.3, you need to use the 2.3 branch of DOM. See the "2.3 branch" sticky.

    Never, ever, ever run a function directly against a query. If it comes back false, you get a fatal error, like you're seeing.

    $map = ($set = DataObject::get("MyThing")) ? $set->toDropdownMap() : array();

    new DropdownField('Foo','Bar',$map);

  • lise
    Avatar
    Community Member
    47 Posts

    Re: How to create an empty DropDownField ? Error in DataObjectManager.php on line 584 Link to this post

    Thank you very much for the tip : I used your code **and** I downloaded the 2.3 version of the DOM (I was running the 2.4 from the
    Modules page ) and it works fine.
    Thanks again - Lise

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