7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Makings items unique per page: DataObjectManager
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 715 Views |
-
Makings items unique per page: DataObjectManager

14 July 2010 at 3:20am
I want each page to contain a list of links, specific to that page. The problem with my code is that is displays the same links on every page.
Each set of links should only be displayed on the page that it was created for.
Page.php
$fields->addFieldToTab("Root.Content.Links", new DataObjectManager(
$this,
'FooterMenuItem',
'FooterMenuItem',
array('Link'=>'Link','Text'=>'Text'),
'getCMSFields_forPopup'
));FooterMenuItem.php
class FooterMenuItem extends DataObject
{
static $db = array (
'Link' => 'Varchar',
'Text' => 'Varchar'
);public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Link'),
new TextField('Text')
);
}
} -
Re: Makings items unique per page: DataObjectManager

14 July 2010 at 4:20am
If you're going to be using the DataObjectManager on subclasses of the object where it is defined, you need to use setParentClass($parent) (in your case, "Page")..
-
Re: Makings items unique per page: DataObjectManager

14 July 2010 at 5:33am
Thanks, where does the setParentClass code go? Do I need to need to change this to has_one or has_many also?
//Page.php
$manager = new DataObjectManager(
$this,
'FooterMenuItem',
'FooterMenuItem',
array('Link'=>'Link','Text'=>'Text'),
'getCMSFields_forPopup'
)$manager->setParentClass('Page');
$fields->addFieldToTab("Root.Content.Links", $manager);
//FooterMenuItem.php
class FooterMenuItem extends DataObject
{
static $db = array (
'Link' => 'Varchar',
'Text' => 'Varchar'
);public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Link'),
new TextField('Text')
);
}
} -
Re: Makings items unique per page: DataObjectManager

14 July 2010 at 5:49am
Make sure Page has $has_many FooterMenuItem and FooterMenuItem $has_one Page.
-
Re: Makings items unique per page: DataObjectManager

14 July 2010 at 6:35am
Thanks but I am still at a loss. How do I make sure Page has $has_many FooterMenuItem and FooterMenuItem $has_one Page?
My code is posted in my previous link.
-
Re: Makings items unique per page: DataObjectManager

14 July 2010 at 7:47am
Have you read the DOM documentation? You need to set up a relationship between Page and FooterLinks.
Page:
static has_many = array (
'FooterLinks' => 'FooterLink'
);FooterLink:
static $has_one = array (
'Page' => 'Page'
);
| 715 Views | ||
|
Page:
1
|
Go to Top |

