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

Having issues with CheckboxSetField - Call to a member function Name() on a non-object


Reply

5 Posts   2059 Views

Avatar
Hammy

20 June 2009 at 12:06pm (Last edited: 20 June 2009 2:38pm), Community Member, 49 Posts

I'm trying to create a CheckboxSetField but I keep on getting the following error message when the CMS Popup appears:
"Fatal error: Call to a member function Name() on a non-object in" ... "\sapphire\forms\FieldSet.php on line 395"

When I remove the checkbox field from the popup it works fine - so I'm sure its isolated to just the CheckboxSetField. I have looked over the Silverstripe documentation and I can't see what I am doing wrong. Below is the code that I am using - Any ideas? (Just in case - I'm using WAMP to develop this site and have updated to the latest stable version - SilverStripe-v2.3.2)

ProductDetail.php

<?php
class ProductDetail extends DataObject {
   
   ...
   
   static $many_many = array(
      'FilterColor' => 'FilterColor',
      ...
   );

   function getCMSFields_forPopup() {
      $FilterColorObj = DataObject::get('FilterColor');
      $FilterColorMap = $FilterColorObj ? $FilterColorObj->toDropdownMap('ID','Title') : array();
      $FilterColorList = new CheckboxSetField(
         'FilterColor',
         'FilterColor',
         $FilterColorMap
      );
      $fields->push( $filterColorList );
      
      ...
      
      return $fields;
   }
   
}

?>

FilterColor.php

<?php
class FilterColor extends DataObject {
   
   static $db = array(
      'Title' => 'Varchar',
      'Hex' => 'Varchar'
   );
   
   public static $belongs_many_many = array(
      'ProductDetail' => 'ProductDetail',
   );
   
   function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push( new TextField( 'Title', 'Colour' ) );
      $fields->push( new TextField( 'Hex', 'Hex', '', 6 ) );
      return $fields;
   }
   
}
?>

Avatar
Sean

20 June 2009 at 1:08pm Forum Moderator, 921 Posts

In ProductDetail you've got a field called "Color", that should be "FilterColor" I believe?

Avatar
Hammy

20 June 2009 at 2:40pm (Last edited: 20 June 2009 2:41pm), Community Member, 49 Posts

Thanks for the pointer but even after the changes (I've updated the code above) I'm still getting the same error message:
"Fatal error: Call to a member function Name() on a non-object in ...\sapphire\forms\FieldSet.php on line 395"

Avatar
Hammy

21 June 2009 at 1:10pm Community Member, 49 Posts

Figured out....

$FilterColorList = new CheckboxSetField(
'FilterColor',
'FilterColor',
$FilterColorMap
);
$fields->push( $filterColorList );

The variable is $FilterColorList and i have tried to push $filterColorList instead (stupid case sensitivity - I can't believe I didn't spot this to begin with.

Avatar
Sean

21 June 2009 at 5:14pm Forum Moderator, 921 Posts

Completely missed that one too!