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.

Customising the CMS /

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

ComplexTableField for all entries


Go to End
Reply


4 Posts   1932 Views

Avatar
madmaurice

Community Member, 20 Posts

6 April 2010 at 4:02am

I try to use the ComplexTableField in a LeftAndMain to allow the user to edit all entries of one type (dataobject)

VIPAdmin.php

<?

class VIPAdmin extends LeftAndMain {
	static $url_segment = "vip";
	
	static $url_rule = '$Action';
	
	static $menu_title = "VIP Editor";
	
	static $menu_property = 60;

	function getEditor() {
		$editor = new ComplexTableField(
			$this,
			'VIPs',
			'VIP',
			array('Name','Spruch'),
			new FieldSet(
				new TextField('Name'),
				new TextareaField('Spruch')
			)
		);
		
		$editor->setParentClass(false);
		
		return new FieldSet($editor);
	}
	
	function VIPs() {
		return DataObject::get('VIP');
	}
}

?>

VIP.php

<?

class VIP extends DataObject {
	static $db = array(
		"Name" => "Varchar(50)",
		"Spruch" => "Text"
	);
	static $has_one = array(
		"Bild" => "Image"
	);
}

?>

VIPAdmin_right.ss

<h1>VIP Editor</h1>

<% if Editor %>
	$Editor
<% else %>
	Kein Editor 
<% end_if %>

if i replace the "return new FieldSet($editor);" with a "return "Hello World!"; " it works. however with the $editor. it shows blank unless the h1-tag

Thx for your help.

ps.: sry for my broken english. im from germany

Avatar
madmaurice

Community Member, 20 Posts

6 April 2010 at 9:58am

when just returning the complextablefield i get a (none).
hope this is helpful

Avatar
madmaurice

Community Member, 20 Posts

6 April 2010 at 10:51pm

Edited: 06/04/2010 11:29pm

Got it with this example: http://doc.silverstripe.org/doku.php?id=leftandmain#subclassing

i needed to use a Form.

Now i got the "i can't sub-URLs of xyz"-Error with my VIPAdmin Thingy

VIPAdmin.php

<?

class VIPAdmin extends LeftAndMain {
	static $url_segment = "vip";
	
	static $url_rule = '$Action';
	
	static $menu_title = "VIP Editor";
	
	static $menu_property = 60;

	function init() {
		parent::init();
		
		//Requirements::css("sapphire/css/ComplexTableField.css");
	}

	function Editor() {
	
		$editor = new ComplexTableField(
			$this,
			'Editor',
			'VIP',
			array('Name','Spruch'),
			'getCMSFields'
		);
		
		//$editor->setReadOnly(false);
		$editor->setCustomSourceItems( DataObject::get('VIP') );
		
		/*$editor->setPermissions(array(
		  	'delete',
		 	'export',
		  	'print',
		  	'edit'
		));*/
		//return $editor;
		return new Form($this,"EditForm",
			new FieldSet(
				new HiddenField('ID', ''),
				$editor
			),
			new FieldSet(new FormAction('go'))
		);
	}
	
	function VIPs() {
		return new DataObjectSet();
	}
}

?>

Url i try to access: http://***/***/admin/vip/EditForm/field/Editor/add
Error i get: I can't handle sub-URLs of a VIPAdmin object.

Avatar
aimcom

Community Member, 8 Posts

24 September 2010 at 9:55pm

I have a similar problem and I'm still looking for a solution (see http://ssorg.bigbird.silverstripe.com/customising-the-cms/show/292590). How did you solve this?