Jump to:

22976 Posts in 11667 Topics by 2826 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 3852 Views
  • edk
    Avatar
    Community Member
    39 Posts

    Re: Holder Pages showing limited number of Child Page Elements Link to this post

    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.

  • Webbower
    Avatar
    Community Member
    10 Posts

    Re: Holder Pages showing limited number of Child Page Elements Link to this post

    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.

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: Holder Pages showing limited number of Child Page Elements Link to this post

    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.

    3852 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.