Jump to:

22999 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Does Object::set_static() actually work??

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

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

Page: 1
Go to End
Author Topic: 761 Views
  • Mo
    Avatar
    Community Member
    485 Posts

    Does Object::set_static() actually work?? Link to this post

    Hi all,

    I have tried on several occasions now to use Object::set_static() to change the Static variable of an object, but it never seems to do anything.

    The best example I can give is while I am trying to change the $url_segment in CMSMain. I use this:

    Object::set_static('CMSMain', 'url_segment', 'cms');

    But it seems to make no difference, if I manually change the variable however, it does what I want to.

    Anyone know whats going on? I do the call in my _config.php file??

    Cheers,

    Mo

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Does Object::set_static() actually work?? Link to this post

    Any particular reason why you want to use Object::set_static instead of simply CMSMain::$url_segment = <value>. What's the advantage of the Object::set_static approach?

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: Does Object::set_static() actually work?? Link to this post

    I have done that, I was just thinking Object::set_static() must be preferred to just directly setting the variable, otherwise I wasn't sure why it would exist...

    Maybe I am thinking too much

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Does Object::set_static() actually work?? Link to this post

    I think the set_static method helps in cases where decorator or "extensions" are being used. So that you can set a static variable that doesn't really belong to the object itself, but to an extension of that object. I'm not really sure though ;)

    But there's nothing wrong with setting the static variable directly. It surely is the better option from a performance point of view.

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: Does Object::set_static() actually work?? Link to this post

    Ok cool, well it seems to be working ok, so I will stick with the direct alteration .

    761 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.