Hi, does anyone know how to create sidebar links based on dataojects? I followed this tutorial: http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/ (as far as sidebars go despite its claim 'simple' it is not!)
Everything works great until you get to the bit about creating sidebars - which I really need!! The bit for reference its spitting out is Controller::CurrentPage(). But anyway I suspect this tutorial is years out of date hence does anyone know of a way in SS3 of creating sidebar links based on dataobjects?
It strikes me as extremely odd that there is not a decent tut on this somewhere which is up to date since to create sidebars of related links is a pretty base requirement I would think! The only difference for me is I want them based on dataobjects not the page tree.
2 July 2014 at 11:15pm
The simplest way to do what you want is to implement a Link() method on your DataObject class. A link method is essentially a way that the a dataobject can connect to a controller to be displayed in the browser.
The tutorial you mentions covers adding the Link method in some detail and it still looks pretty relevent, so withour seeing any of your code, I would suggest that is the first place to look?
Cheers Mo - I'll have a look at that tut again - the problem I have is it chokes on the CurrentPage controller. telling me that it does not exist which made me think Oh hang on this old code. - section below:
public function LinkingMode()
//Check that we have a controller to work with and that it is a StaffPage
if(Controller::CurrentPage() && Controller::CurrentPage()->ClassName == 'StaffPage')
//check that the action is 'show' and that we have a StaffMember to work with
if(Controller::CurrentPage()->getAction() == 'show' && $StaffMember = Controller::CurrentPage()->getStaffMember())
//If the current StaffMember is the same as this return 'current' class
return ($StaffMember->ID == $this->ID) ? 'current' : 'link';
3 July 2014 at 11:08am
Glad you got it sorted. Looking at you code again, it looks like the exact issue you were having was in the LinkingMode method. This is actually used to determine if the link is the page you are viewing is the current page (allowing you to add for example an active state).
As you say Controller::curr() is the SilverStripe 3.x way of accessing the current controller, not Controller::current page().