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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Reply

5 Posts   877 Views

Avatar
MagicUK

16 August 2011 at 9:42am Community Member, 60 Posts

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

17 August 2011 at 1:58am 4085 Posts

You run them against a DataObjectManager instance..

$yourDOM->setPageSize(50);

Avatar
MagicUK

17 August 2011 at 2:06am Community Member, 60 Posts

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

17 August 2011 at 4:56am 4085 Posts

$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

17 August 2011 at 5:25am Community Member, 60 Posts

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