1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Options not workin?

Discussion in 'XenForo Development Discussions' started by Mr. Goodie2Shoes, Jun 26, 2012.

  1. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    well... I am creating a new dynamic BBCode which needs to managed by an Add-on... mainly for enabling the BBCode... so I tried to 'fetch' the options using
    PHP:
    XenForo_Application::get('options');
    but I am getting this error:
    Code:
    Fatal error: Cannot use object of type XenForo_Options as array
    any help? :(
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    That should work...

    Code:
    $options = XenForo_Application::get('options');
     
    if ($options->addonEnable)
    {
    echo 'Add on enabled'
    }
    If I have an on/off checkbox option called addonEnable set up that's ticked then "add on enabled" will be echoed.

    Are you doing something like $options['addonEnable'] as that won't work.
     
    Mr. Goodie2Shoes likes this.
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    but its working for all my other add-ons o_O
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Yet, when I use $options['addonEnable'] in any of mine then I get this error:

    Fatal error: Cannot use object of type XenForo_Options as array in Listener.php on line 10

    Does $options->optionName work? I've never seen it done differently.
     
  5. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Yes, your way works... :)
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    I've just checked one of your add-ons.

    You usually do load options as an array like this:

    Code:
    $options = XenForo_Application::get('options')->getOptions();
    The way you've done it in your original post is loading it as an Object. As a result, you'll get an error if you try to load it as an array.

    So basically you are absolutely right in your first post, but you're missing ->getOptions()
     
  7. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    ah yes... :D
    damn silly mistakes :oops:
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    I make them all the time :D

    I'll tell you this because there's no shame in making mistakes...

    I recently released an add-on that displays user's age in the message user info section.

    I released it but got confused between $visitor and $user.

    As a result, moments after releasing it I realised on my test forum everyone's age was displayed as the same... it was displaying my age not the user's age.

    I then deleted it while I fixed it :p

    Doh!
     
  9. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

  10. ragtek

    ragtek Guest

    They should have called the method toArray instead of getOptions

    Then it would be easier to understand, because everything else uses toArray (like with the visitor object)
     

Share This Page