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

DataObject with link to page


Reply


2 Posts   965 Views

Avatar
k0m0r

Community Member, 39 Posts

16 July 2010 at 12:02am

Edited: 16/07/2010 12:04am

Hi.
I'm stuck at the following:

class MyLink extends DataObject {

public static $db = array(
"Title" => "Varchar(255)",
);

public static $has_one = array(
"ParentPage" => "SiteTree",
"PagePointer" => "SiteTree",
);

function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField('Title','Link title'));
$fields->push(new SimpleTreeDropdownField('PagePointerID','Select page'));      
return $fields;
}   
}

and on MyErrorPage :

class MyErrorPage extends ErrorPage {

public static $has_many = array(
"LinkList" => "MyLink",
);

function getCMSFields() {
$fields = parent::getCMSFields();
      
$manager = new DataObjectManager(
$this,
'LinkList',
'MyLink',
array(
"Title" => "Title",
),
'getCMSFields_forPopup'
);

$fields->addFieldToTab('Root.Content.LinkList',$manager);
return $fields;
}

}

When I comment out 'PagePointer' and SimpleTreeDropdownField from 'MyLink' class, everything works perfect. I can add MyLink items in DOM and then list them in a control (at MyErrorPage):

<% control LinkList %>
<li>$Title</li>
<% end_control %>

But after adding this:

"PagePointer" => "SiteTree",

and this:

$fields->push(new SimpleTreeDropdownField('PagePointerID','Select page'));

and rebuilding the database, LinkList control stops working. It doesn't matter if I set the value of PagePointerID or not, <% control LinkList %> is just empty, not a single item being shown.

I triple checked everything, what am I missing here?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

16 July 2010 at 2:24am

Your $has_many relationship is not reciprocated with a $has_one. Link needs to have a $has_one MyErrorPage (or wherever the DOM is). That's the data relationship that counts. $has_many just creates the template function.