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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Pagetype inheriting full db?


Reply


6 Posts   1164 Views

Avatar
Karai

Community Member, 13 Posts

22 May 2009 at 1:27am

http://pastebin.com/m6e0cc5ce

Those are my Page.php and HomePage.php files, cut down to only show the relevant parts. The problem I'm having is on my Home page, it is displaying all of the RelatedLinks from the other pages, and does not have any unique to itself. I can't for the life of me figure out why this is happening...

Avatar
Carbon Crayon

Community Member, 598 Posts

22 May 2009 at 2:08am

Edited: 22/05/2009 3:45am

EDIT: yea sorry totally misunderstood that one :)

Avatar
UncleCheese

Forum Moderator, 4096 Posts

22 May 2009 at 2:30am

Common problem. You've passed $this as the controller for the DOM, so when it updates your RelatedLink object, by default, it will try to set the foreign key {ControllerPage}ID. When the controller page is a Page object, that works fine (PageID). But when it's a HomePage, or any other subclass of page, that will fail when it tries to set HomePageID on your RelatedLink object.

Solution:

->setParentClass('Page');

Avatar
Karai

Community Member, 13 Posts

22 May 2009 at 2:35am

Edited: 22/05/2009 2:35am

I think I understand, so in Page.php I change $this to $this->setParentClass('Page'), or am I way off?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

22 May 2009 at 3:12am

No, you need to run that function on the DataObjectManager

$manager = new DataObjectManager(
...

);

$manager->setParentClass('Page');

Avatar
Karai

Community Member, 13 Posts

22 May 2009 at 4:08am

Amazing, it works! Thank you!

//related links tab   
$fields->addFieldToTab("Root.Content.RelatedLink",
   $manager = new DataObjectManager(
      $this,
      'RelatedLinks',
      'RelatedLink',
      array('Title' => 'Title','Address'=>'Address'),
      'getCMSFields_forPopup'
   )
);

$manager->setParentClass('Page');