Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 638 Views
  • grumpypanda
    Avatar
    Community Member
    32 Posts

    SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue Link to this post

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

  • Sticks
    Avatar
    Community Member
    29 Posts

    Re: SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue Link to this post

    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.

  • grumpypanda
    Avatar
    Community Member
    32 Posts

    Re: SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue Link to this post

    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
       

  • grumpypanda
    Avatar
    Community Member
    32 Posts

    Re: SSBITS: DataObjects as Pages Part 2 tutorial- sidebar issue Link to this post

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

    638 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.