It's look simple, but I looked at many posts and I dont found working for me solution. I've got a page with portfolio. This is one page with realisations. Each single realisation subpage is a dataobject. On each one from this subpages I need two buttons: Next and Prev. How to do it?
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.
- Page 11(current)
- 2
- Next 10 entries
$prev=$this->Parent()->Children()->filter(['Sort'=>$this->Sort-1]);
//or
$next=SiteTree::get()->filter(['ParentID'=>$this->ParentID,'Sort'=>$this->Sort+1]);
Thanks for your reply. Unfortunately I've got an error with this code: Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'Portfolio'
This pages are not childrens. They are dataobjects like in this tutorial: http://docs.silverstripe.org/en/3.1/tutorials/extending_a_basic_site/
In that case it's harder, without a defined sort.
I believe the default is creation date (which is bascially the ID).
So then
$this->WhateverTheHasOneToTheParentIsNamed()->WhateverTheHasManyToTheseRelatedPortfolioObjectsIsCalled()->filter('Created:GreaterThan',$this->Created)->first()
use the :LessThan filter for prev.
Or
Portfolio::get()->filter(['ParentRelationNameID'=>$this->ParentRelationNameID, 'Created:LessThan'=>$this->Created])->First()
Where the names of your relations are appropriate (I guess 'PortfolioHolder' maybe?)
Summary page is PortfolioPage. I have errors with your code "unexpected ] ", so I changed it to:
public function PreviousPage() {
Portfolio::get()->filter(array('PortfolioPageID'=>$this->PortfolioPageID, 'Created:LessThan'=>$this->Created))->First();
}
public function NextPage() {
Portfolio::get()->filter(array('PortfolioPageID'=>$this->PortfolioPageID, 'Created:GreaterThan'=>$this->Created))->First();
}
but I dont see nothing on site.
SS is
<% loop $PreviousPage %>$Title<% end_loop %> <% loop $NextPage %>$Title<% end_loop %>
You need to return those.
return Portfolio::get()->...;
and you should use <% with $NextPage %>, not <% loop %> since you are retrieving a single object, not a list of objects.
Or alternatively $NextPage.Title (etc)
You have right. Thank you for your help.
This almost work for me:
public function PreviousPage() {
return $this->PortfolioPage()->Portfolio()->filter('ID:LessThan',$this->ID)->first() ;
}
//or
public function NextPage() {
return $this->PortfolioPage()->Portfolio()->filter('ID:GreaterThan',$this->ID)->first() ;
}
Next work like charm, but previous show allway firts item with ID =1
Final working code:
PortfolioPage is page
Portfolio extends DataObject {$has_many)
php
public function PreviousPage() {
return $this->PortfolioPage()->Portfolio()->filter('ID:LessThan',$this->ID)->sort(array( 'ID' => 'DESC'))->first() ;
}
public function NextPage() {
return $this->PortfolioPage()->Portfolio()->filter('ID:GreaterThan',$this->ID)->sort(array( 'ID' => 'ASC'))->first() ;
}
ss
<% with $PreviousPage %>$Title <% end_with %> <% with $NextPage %>$Title <% end_with %>
I realy thank you once again. Without you I lost many hours.
- Page 11(current)
- 2
- Next 10 entries