Jump to:

7936 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [RESOLVED] Set Default Behaviour of 'Results Per Page'

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 851 Views
  • MagicUK
    Avatar
    Community Member
    60 Posts

    [RESOLVED] Set Default Behaviour of 'Results Per Page' Link to this post

    Hey All. Was hoping for a bit of help again.

    I have the folowing code defining a page which works great:

    Speakerpage.php

    <?php
    class SpeakersPage extends SiteTree {
    public static $db = array(
    'RightContent' => 'HTMLText',
    );
    public static $many_many = array(
    'Speakers' => 'Speaker',
    'KeyNoteSpeakers' => 'Speaker',
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab( 'Root.Content.Speakers', new ManyManyDataObjectManager(
    $this,
    'Speakers',
    'Speaker'
    ));

    $fields->addFieldToTab( 'Root.Content.KeyNoteSpeakers', new ManyManyDataObjectManager(
    $this,
    'KeyNoteSpeakers',
    'Speaker'
    ));

    return $fields;
    }
    }
    ...

    Having looked around I can see that the functions I'm looking for to change the default behaviour of the 'results per page' on my cms are

    $myDOM->setPerPageMap();
    $myDOM->setPageSize();

    Problem is I'm not sure as per the above code where to put these functions?

    I've tried below but this causes the site to break? Any suggestions of what I am doing wrong?

    <?php
    class SpeakersPage extends SiteTree {
    public static $db = array(
    'RightContent' => 'HTMLText',
    );
    public static $many_many = array(
    'Speakers' => 'Speaker',
    'KeyNoteSpeakers' => 'Speaker',
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab( 'Root.Content.Speakers', new ManyManyDataObjectManager(
    $this,
    'Speakers',
    'Speaker'
    ));

    $fields->addFieldToTab( 'Root.Content.KeyNoteSpeakers', new ManyManyDataObjectManager(
    $this,
    'KeyNoteSpeakers',
    'Speaker'
    ));

    $fields->setPageSize(50);

    return $fields;
    }
    }
    ...

  • UncleCheese
    Avatar
    4085 Posts

    Re: [RESOLVED] Set Default Behaviour of 'Results Per Page' Link to this post

    You run them against a DataObjectManager instance..

    $yourDOM->setPageSize(50);

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: [RESOLVED] Set Default Behaviour of 'Results Per Page' Link to this post

    Thanks for the reply unclleCheese. I tried that as per the code above

    $fields->setPageSize(50);

    and it didn't work. Getting an 'error on the cms everytime I try to access the page. Is it because I have two doms running on that page with the same name?

  • UncleCheese
    Avatar
    4085 Posts

    Re: [RESOLVED] Set Default Behaviour of 'Results Per Page' Link to this post

    $fields is a FieldSet object, not a DataObjectManager.

    $fields->addFieldToTab("Root.Content....", $dom = new DataObjectManager(.....));

    $dom->setPageSize(50);

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: [RESOLVED] Set Default Behaviour of 'Results Per Page' Link to this post

    Thanks sir. That did the trick. I just assumed $fields was a variable for the dom. Need to look into that one.

    851 Views
Page: 1
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.