Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Vanilla 2.6 is here! It includes security fixes and requires PHP 7.0. We have therefore ALSO released Vanilla 2.5.2 with security patches if you are still on PHP 5.6 to give you additional time to upgrade.

Does storing config values in protected vars makes sense?

R_JR_J Cheerleader & TroubleshooterMunich Moderator

I'm toying around with the recent discussion list and want to add content to each discussion, based on a config setting.
Getting values from the config needs accessing config-defaults.php as well as config.php - at least that's what I think is true when you are using DirtyCache - and so I hope there is a possibility to read that value only one time and store it for all usages on that page access.

I'm thinking of something like that in my plugin:

protected $_ConfigValue;

public function __construct() {
    $this->$_ConfigValue = Gdn::Config('Plugins.MyPlugin.ConfigValue', 250);
}

public function discussionsController_afterDiscussionContent_handler($Sender) {
    // Now using $this->$_ConfigValue instead of
    // Gdn::Config('Plugins.MyPlugin.ConfigValue', 250)
}

Would that have any advantages over simply using Gdn::Config()?

I do not have any knowledge about the "lifetime" of my class. And if my class is constructed more than one time when recent discussions is build up, it would make no sense at all, I think. But when my function __construct is only called once in recent discussions, it would be clever, wouldn't it?

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Thanks for that! I found it not being shorter, but bloated - but it made me feel like a genius for a few minutes... :D

    hgtonightperegrineUnderDog
  • hgtonighthgtonight ∞ · New Moderator

    @R_J said:
    ...it made me feel like a genius for a few minutes... :D

    I get that feeling every time I discover some core functionality, only to realize I used it in another plugin already!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    R_JperegrineUnderDogLinc
  • @hgtonight said:
    @R_J said:

    ...it made me feel like a genius for a few minutes... :D

    I get that feeling every time I discover some core functionality, only to realize I used it in another plugin >already!

    both you guys @r_j and @hgtonight are genuises for well over an hour extending into days and weeks and beyond. Always interesting posts and solutions.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.