Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

1155 Posts in 324 Topics by 274 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Problems with Object::useCustomClass

Page: 1
Go to End
Author Topic: Problems with Object::useCustomClass 942 Views
  • briansohn
    avatar
    Community Member
    5 posts

    Problems with Object::useCustomClass Link to this post

    Hello,

    I am trying to override a function in the LeftAndMain class in the 'cms' module.

    I have put the following in mysite/_config.php

    Object::useCustomClass('LeftAndMain', 'CustomLeftAndMain');

    I have extended the LeftAndMain class in CustomLeftAndMain class and have overridden the getSiteTreeFor() function but it has no effect.

    Any help would be greatly appreciated.

    Thanks!

    Brian Sohn

  • Hamish
    avatar
    Community Member
    609 posts

    Re: Problems with Object::useCustomClass Link to this post

    Never tried that before, but see if this works:

    Object::useCustomClass('LeftAndMain', 'CustomLeftAndMain', true);

  • briansohn
    avatar
    Community Member
    5 posts

    Re: Problems with Object::useCustomClass Link to this post

    Hey Hamish,

    Thanks for the feedback. I have tried the 'true' flag and it still doesn't work. If you come across anything give me a shout. I'll keep looking back to this thread.

    Thanks.

  • briansohn
    avatar
    Community Member
    5 posts

    Re: Problems with Object::useCustomClass Link to this post

    I was looking through the Object class and it looks like only classes that are created by using the Object::create() static method can be replaced with custom classes.

    for example in the Sapphire folder,

    Member
    MemberLoginForm

    can be replaced with a custom class.

  • Hamish
    avatar
    Community Member
    609 posts

    Re: Problems with Object::useCustomClass Link to this post

    I don't have a solution for the applying the custom class, but if you want to override the getSiteTreeFor method for the main CMS editor then this might work:

    1. Create a new CustomCMSMain class that extends CMSMain with your new getSiteTreeFor method.

    2. Edit your _config.php to direct cms requests to your new CMSMain class:

    Director::addRules(100,array('admin/cms//$Action/$ID/$OtherID' => 'CustomCMSMain'));

    (I think priorities go from high to low... so this should override the '50' in /cms/_config.php)

    3. It might cause a double-up in the menu, so you might have to add this to the _config.php file too:

    CMSMenu::remove_menu_item("CMSMain");

    Let me know if this works

    942 Views
Page: 1
Go to Top

Currently Online: jseth, dizzystuff

Welcome to our latest member: holy noli

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

Comments on this website? Please give feedback.