21294 Posts in 5734 Topics by 2602 members
General Questions
SilverStripe Forums » General Questions » Holder Pages showing limited number of Child Page Elements
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | ||
| Author | Topic: | 3081 Views |
-
Re: Holder Pages showing limited number of Child Page Elements

29 January 2011 at 4:08pm
Thanks MonkeyBen and Webbower. The issue is now *SOLVED* thanks to your input.
For someone reading this in the future bleary eyed and frustrated at 2am in the morning
here is the scoop when working with a has many relationship in a classic SilverStripe PageHolder / Page setup. In short Webbower was spot on. The method call to the get the children of the ImageGalleryPage had to be in the Page subClass block and not in the Page_Controller block. As soon as I moved the method up to the Page subClass block the call using $this recognized its current scope and was able to get it associated has many relationship.
class ImageGalleryPage extends Page {
static $db = array(
'GalleryTitle' => 'Text',
'GalleryExcerpt'=> 'Text'
);
static $has_many = array (
'ImageGalleryPageImages' => 'ImageGalleryPageImage'
);function ImageGalleryShowNum($num = 6) {
$results = $this->getComponents('ImageGalleryPageImages', '', 'SortOrder DESC', '', $num);
return $results;
}
}So if you are looking to iterate over you Pages in a holder relationship and those Pages have a has many relationship just follow this style to get at the data you need.
-
Re: Holder Pages showing limited number of Child Page Elements

30 January 2011 at 7:06am
Alternatively, if you MUST have it in your Controller subclass the following should work, but it must be in the Controller subclass that is paired with the Page subclass:
function ImageGalleryShowNum($num = 6) {
$results = $this->data()->getComponents('ImageGalleryPageImages', '', 'SortOrder DESC', '', $num);
return $results;
}Calling $this->data() in your Controller subclass will return the paired Page subclass instance.
-
Re: Holder Pages showing limited number of Child Page Elements

7 May 2011 at 5:07am
Thank you very much edk. You saved my night
For last two hours I was trying to solve this issue. I tried everything except putting the function in the subclass. Thank you for great tip.
| 3081 Views | ||
| Go to Top |



