7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DataObject with link to page
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: | 699 Views |
-
DataObject with link to page

16 July 2010 at 12:02am Last edited: 16 July 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?
-
Re: DataObject with link to page

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.
| 699 Views | ||
|
Page:
1
|
Go to Top |

