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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue


Go to End


4 Posts   1674 Views

Avatar
grumpypanda

Community Member, 32 Posts

23 January 2012 at 3:58pm

Hi everyone,

I've been following http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/ tutorial on my localhost and running into a sidebar problem.

When I use the same method to create a sidebar as tutorial one, an error message shows on my site: [User Error] Uncaught Exception: Object->__call(): the method 'categorypages' does not exist on 'Product'

I know someone had this problem before, but the solution in the discussion didn't solve my problem since I am using the new code ($Category = $this->Categories()->First(); on line 120).

This is the code I added to Product.php for sidebar to appear.

//Return the Title as a menu title
public function MenuTitle()
{
return $this->Title;
}

//Ensure that the DO shows up in menu (it is needed otherwise sidebar doesn't show when not logged in)

function canView()
{
return $this->CategoryPages()->canView();
}

Does anyone know how to fix it? Thanks very much.

Sam:)

Avatar
Sticks

Community Member, 31 Posts

23 January 2012 at 4:26pm

Edited: 23/01/2012 4:27pm

Hi SamIAm, if you've declared the Category Pages as in the tutorial:

    //Relate to the category pages
    static $belongs_many_many = array(
        'Categories' => 'CategoryPage'
    );

...then your canView function should look like this:

function canView()
{
return $this->Categories()->canView();
} 

ie. Change CategoryPages() to Categories() (or whatever you have named the relationship).

Now I'm not 100% on whether that'll make the overall functionality work but I'm pretty sure that's where the error is originating, and that's where I'd start.

Avatar
grumpypanda

Community Member, 32 Posts

24 January 2012 at 8:21am

Hi Sticks,

Thanks very much for replying. You are right that I need to change

function canView()
{
return $this->CategoryPages()->canView();
}

to return $this->Categories()->canView();

However another error came up, [User Error] Uncaught Exception: Object->__call(): the method 'canview' does not exist on 'ComponentSet' Any suggestions on how to fix this?

Thanks very much for your help.

Sam

Avatar
grumpypanda

Community Member, 32 Posts

25 January 2012 at 8:52am

This is for people who run into the same problem just in case. People on other site have suggested me to use 'return true' for my sidebar purpose and it is working now. Cheers, S:)