Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » Having issues with CheckboxSetField - Call to a member function Name() on a non-object

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: 2002 Views
  • Hammy
    Avatar
    Community Member
    49 Posts

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

    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;
       }
       
    }
    ?>

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Having issues with CheckboxSetField - Call to a member function Name() on a non-object Link to this post

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

  • Hammy
    Avatar
    Community Member
    49 Posts

    Re: Having issues with CheckboxSetField - Call to a member function Name() on a non-object Link to this post

    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"

  • Hammy
    Avatar
    Community Member
    49 Posts

    Re: Having issues with CheckboxSetField - Call to a member function Name() on a non-object Link to this post

    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.

  • Sean
    Avatar
    Forum Moderator
    921 Posts
    2002 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.