7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [SOLVED] Show related object title
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: | 1096 Views |
-
[SOLVED] Show related object title

21 August 2009 at 5:00am Last edited: 21 August 2009 9:48pm
Ok, so this should be my last question for today!
I've managed to implement a relationship along with the DOM, but can't work out how to display the relationship in the admin page.
I've got a NewsArticle object with four fields: Date, Author, News content, and Category.
The Category is connected through a one -> many relationship (each article can have one category, category can have many articles).
I've got the DOM to display just the Category ID that's been assigned to the NewsArticle object - but would like to display (and filter by category).
Here's my code: http://pastie.org/590006
Does anyone know what I need to do to get it working?
Is there something basic I'm missing, or need to understand how the headers array can accept data?
All help is much appreciated!
L
-
Re: [SOLVED] Show related object title

21 August 2009 at 5:16am
In your headings array, you should be able to do:
array('NewsCategory.Title' => 'News category title');
But if that doesn't work, just use a custom getter.
getNewsCategoryTitle()
{
return $this->NewsCategory()->Title;
}array('NewsCategoryTitle' => 'News category title');
-
Re: [SOLVED] Show related object title

21 August 2009 at 5:21am
Hi Uncle Cheese,
I feel like a bit of a dolt this afternoon, but how do I implement a custom getter?
Does that need to be put in the header array, inside the getCMSFields function, or made as a function of its own in some way?
I tried NewsContent.Title, and it just returned the id with a hash (pound) symbol in front of it...
Cheers
L
-
Re: [SOLVED] Show related object title

21 August 2009 at 5:38am
You put the custom getter in the model for the class you're viewing in the DOM. In your case, that's NewsArticle, I believe.
-
Re: [SOLVED] Show related object title

21 August 2009 at 9:48pm
Thanks for your help on this Uncle Cheese!
It's all working just as I need it to
I'll make a post with my final code so others can share at somepoint this weekend.
L
| 1096 Views | ||
|
Page:
1
|
Go to Top |

