One last silly mistake, now all works. Change Row2() to:
function Row2() {
$Total = ($this->Sponsors()->Count()) ;
$Half = ceil(($Total / 2));
return DataObject::get("SponsorPage", "", "", "", "$Half, $Total");
}
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
One last silly mistake, now all works. Change Row2() to:
function Row2() {
$Total = ($this->Sponsors()->Count()) ;
$Half = ceil(($Total / 2));
return DataObject::get("SponsorPage", "", "", "", "$Half, $Total");
}
I am trying to adapt this to three columns. I have set up my PHP thusly:
function Row1() {
$Part = ceil(($this->Articles()->Count()) / 3);
return DataObject::get("ArticlePage", "", "", "", "0, $Part");
}
function Row2() {
$Part = ceil(($this->Articles()->Count()) / 3);
$Part2 = floor(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Part, $Part2");
}
function Row3() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 3));
$Break = ceil(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Break, $Total");
}
}
Example: Let's say there are 6 items.
Row 1
Item 1
Item 2
Row 2
Item 3
Item 4
Item 5
Item 6
Row3
Item 5
Item 6
Any ideas why it's breaking down like that? The calculation for $Part2 should be correct since it's the same as $Break and Row 3 is starting in the correct place. I'm not a PHP programmer so I can only assume the last parameter in the Get statement indicates "start, end"
Thanks,
Joe
UPDATE: I figured out what my problem was. I was assuming that the last parameter meant "starting record number, ending record number" when in actuality it means "starting record number, number of records to display." It works now!
Row 2 code should read:
function Row2() {
$Part = ceil(($this->Articles()->Count()) / 3);
return DataObject::get("ArticlePage", "", "", "", "$Part, $Part");
}
If you wanted to add a 4th segment, change all of the 3's to 4's and change the following:
function Row3() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 4));
$Begin = ceil(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Begin, $Part");
}
function Row4() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 3));
$Begin = ceil(($Part * 3));
return DataObject::get("ArticlePage", "", "", "", "$Begin, $Total");
}
Old post, but i'll give it try...
I like the idea, but my problem is (maybe) a little more challenging.
I have my records display in alphabetical range
public function AlphabeticalItems()
{
$r = $this->getRequest()->getVar('range');
if(!$r)
{
$r = "A-D"; //default reange to show
}
list($start, $end) = explode("-",$r);
return DataObject::get("Dog","PedigreeName > '$start' AND PedigreeName < '$end'","PedigreeName ASC");
}
Now i've tried to use 'AlphabeticalItems' like you used 'sponsors' but that only returns row 1 of my A-D range. It never shows row2 and offcourse it doesn't show my next ranges.
I got that since my Row1 never goes back to my function 'AlphabeticalItems'
So i need to display my ranges in two columns.
Any ideas on this one?