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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue


Reply

4 Posts   719 Views

Avatar
grumpypanda

23 January 2012 at 3:58pm Community Member, 32 Posts

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

23 January 2012 at 4:26pm (Last edited: 23 January 2012 4:27pm), Community Member, 29 Posts

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

24 January 2012 at 8:21am Community Member, 32 Posts

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

25 January 2012 at 8:52am Community Member, 32 Posts

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:)