Options not workin?

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? :(
 
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.
 
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.
 
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()
 
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!
 
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)
 
Top Bottom