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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

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


Go to End


5 Posts   3190 Views

Avatar
Hammy

Community Member, 49 Posts

20 June 2009 at 12:06pm

Edited: 20/06/2009 2:38pm

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

Forum Moderator, 922 Posts

20 June 2009 at 1:08pm

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

Avatar
Hammy

Community Member, 49 Posts

20 June 2009 at 2:40pm

Edited: 20/06/2009 2:41pm

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

Community Member, 49 Posts

21 June 2009 at 1:10pm

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

Forum Moderator, 922 Posts

21 June 2009 at 5:14pm

Completely missed that one too!