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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

TableField


Go to End


575 Views

Avatar
kindleman.com.au

Community Member, 70 Posts

10 November 2011 at 7:27pm

Edited: 10/11/2011 7:27pm

Hello

I'm trying to use TableField to manage a list of related links to a page. I have the control working, except it isn't saving the id to the db (a hidden field), just the title and url

Is this the right way to be using it? think so. I've been using this: http://doc.silverstripe.org/sapphire/en/reference/tablefield as a guide

some code:

static $has_many = array (
		'Linketys' => 'Linkety',  		
	);

$myTableField = new TableField(
		  'MyTableField', // fieldName
		  'Linkety', // sourceType
		  array(
		    'Title'=>'Title',
		    'URL'=>'URL'
		  ), // fieldList
		  array(
		    'Title'=>'TextField',
		    'URL'=>'TextField'
		  ), // fieldTypes
		  null, // filterField (legacy)
		  "Linkety.PageID",
		  $this->ID
		);
		// add some HiddenFields thats saved with each new row
		$myTableField->setExtraData(array(
		  'PageID' => $this->ID ? $this->ID : '$RecordID'
		));
		$fields->addFieldToTab("Root.Content.Options", $myTableField);