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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Create sidebars based on dataobjects


Go to End


6 Posts   1447 Views

Avatar
tahbit

Community Member, 24 Posts

2 July 2014 at 10:57pm

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.

Really grateful for any feedback on this.

Avatar
Mo

Community Member, 541 Posts

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

Avatar
tahbit

Community Member, 24 Posts

3 July 2014 at 2:11am

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:

<codeblock>
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';
}
}
}
</codeblock>

Avatar
tahbit

Community Member, 24 Posts

3 July 2014 at 2:28am

I have followed the tut to the letter and amended for SS3 where appropriate and got it working up to the point I want to include the sidebar - I just end up with this error.

Fatal error: Call to undefined method Controller::CurrentPage()

What is the CurrentPage controller? Do I have to create it? Is this something I have to route to? Has it been deprecated in SS3?

There are no clues in the tut and nothing in the forums - the trail just goes cold! Grateful for your thoughts.

Avatar
tahbit

Community Member, 24 Posts

3 July 2014 at 2:46am

Hi Mo,

Thanks for your guidance on this - you were right - the answer is in the Tut.

Controller::curr() replaces Controller::CurrentPage() - Once I sorted that it was happy days!

But thing is I did check that thinking, hmmm, but could not find anything on it straight away... Anyway - resolved thanks to you suggesting I look again.

Grateful!

Avatar
Mo

Community Member, 541 Posts

3 July 2014 at 11:08am

Hi Tahbit,

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().

Cheers,

Mo