21300 Posts in 5735 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 726 Views |
-
How to set up TableField

6 April 2011 at 7:42pm
I would like to add a TableField to a tab in the CMS to simple add a list of hyperlinks (title + link) to a page. Problem: in my current setup when I change/add a hyperlink on a page, the change is reflected on all other pages as well. What should I change to prevent this from happening?
//mysite/code/Hyperlink.php
<?php
class Hyperlink extends DataObject
{
static $db = array (
'Title' => 'Text',
'Link' => 'Text'
);static $has_one = array (
'CaseExamplePage' => 'CaseExamplePage'
);public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Title'),
new TextField('Link')
);
}}
?>
//mysite/code/CaseExamplePage.php
<?php
class CaseExamplePage extends Page {public static $has_many = array(
'Hyperlinks' => 'Hyperlink'
);public function getCMSFields() {
$fields = parent::getCMSFields();
// Add Hyperlinks tab
$tblf = new TableField(
//$this,
'Hyperlinks',
'Hyperlink',
array('Title' => 'Title', 'Link' => 'Link'),
array('Title' => 'TextField', 'Link' => 'TextField'),
null,
"Hyperlink.CaseExamplePageID",
$this->ID
);
$fields->addFieldToTab('Root.Content.Hyperlinks', $tblf);(...)
-
Re: How to set up TableField

16 May 2012 at 7:48am
Check the parameters of the TableField constructor. I think it should be:
$tblf = new TableField(
'Hyperlinks',
'Hyperlink',
array('Title' => 'Title', 'Link' => 'Link'),
array('Title' => 'TextField', 'Link' => 'TextField'),
"CaseExamplePageID",
$this->ID
);Jonathan.
| 726 Views | ||
|
Page:
1
|
Go to Top |


