Silverstripe ComplexTableField
I was following the tutorial about Silverstripe DataObjects, in the helpful book “Silverstripe CMS Development” by Ingo Schommer and Steve Broschart. My page which listed by objects as displayed OK in the admin interface. However, when I clicked the “Add XXXXXX” button to add my first data record, the popup which appeared showed the bewildering message
Fatal error: Call to a member function removeByName() on a non-object in C:\work\xampp\htdocs\portal.test\sapphire\forms\ComplexTableField.php on line 536
It took a while to figure out what I had done wrong, and this may help you too. My data object had this code:
function getCMSFields() { $form_fields = new FieldSet( new TextField('Name', 'Service name'), new TextField('Description', 'Description'), new TextField('URL', 'Web page for more info') ); return $fields; }
and my silly mistake was imply that I used “return $fields”, which should be “return $form_fields”. The CMS was understandably unable to find a list of my form fields. The “non-object” is an empty list of the fields returned by my getCMSFields. It all makes sense really.