Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

[RESOLVED] Set Default Behaviour of 'Results Per Page'


Go to End


5 Posts   1389 Views

Avatar
MagicUK

Community Member, 60 Posts

16 August 2011 at 9:42am

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; 
} 
} 
...

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 August 2011 at 1:58am

You run them against a DataObjectManager instance..

$yourDOM->setPageSize(50);

Avatar
MagicUK

Community Member, 60 Posts

17 August 2011 at 2:06am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 August 2011 at 4:56am

$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

Avatar
MagicUK

Community Member, 60 Posts

17 August 2011 at 5:25am

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