7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Getting related Objects [RESOLVED]
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: | 605 Views |
-
Getting related Objects [RESOLVED]

11 August 2011 at 7:29am
I can't figure out how to display the "Resources Link" under there appropriate "Resource Link Category" any help?
Here's the code.
ResourceLinkCategory.php
class ResourceLinkCategory extends DataObject {
static $db = array('Name' => 'Text');
static $has_many = array('ResourceLinks' => 'ResourceLink');function getCMSFields_forPopup() {
$fields = new FieldSet();$fields->push (new TextField('Name'));
return $fields;
}
}ResourceLink.php
class ResourceLink extends DataObject {
static $db = array(
'URL' => 'Text',
'Description' => 'Text'
);
static $has_one = array(
'ResourceLinkPage' => 'ResourceLinkPage',
'MyResourceLinkCategory' => 'ResourceLinkCategory'
);function getCMSFields_forPopup() {
$fields = new FieldSet();$fields->push (new TextField('URL'));
$fields->push (new TextareaField('Description'));
$fields->push (new HasOneDataObjectManager(
$this,
'MyResourceLinkCategory',
'ResourceLinkCategory',
array('Name' => 'Name'),
'getCMSFields'
));return $fields;
}
}ResourceLinkPage.php
class ResourceLinkPage extends Page {
static $has_many = array(
'ResourceLinks' => 'ResourceLink',
'ResourceLinkCategories' => 'ResourceLinkCategory'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$resourcelinks = new DataObjectManager(
$this,
'ResourceLinks',
'ResourceLink',
array(
'URL' => 'URL',
'Description' => 'Description'
),
'getCMSFields_forPopup'
);
$fields->addFieldToTab('Root.Content.ResourceLinks', $resourcelinks);
return $fields;
}
}class ResourceLinkPage_Controller extends Page_Controller {
function GetResourceLinkCategories() {
return DataObject::get('ResourceLinkCategory', '', '', '', '');
}
}ResourceLinkPage.ss
<% control GetResourceLinkCategories %>
<h2><span>$Name</span></h2>
<-- Display Resources Link related to the Category here -->
<% end_control %> -
Re: Getting related Objects [RESOLVED]

11 August 2011 at 9:38am
<% control GetResourceLinkCategories %>
<h2><span>$Name</span></h2>
<% control ResourceLinks %>
<!-- Resource link stuff here -->
<% end_control %>
<% end_control %>There's always a method available with the same name as the relationship which acts as a getter for all related objects.
-
Re: Getting related Objects [RESOLVED]

11 August 2011 at 10:00am
*sigh* I need some sleep. Thanks that works just like it should.
| 605 Views | ||
|
Page:
1
|
Go to Top |


