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

Options not workin?

Mr. Goodie2Shoes

Well-known member
#1
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? :(
 

Chris D

XenForo developer
Staff member
#2
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.
 

Chris D

XenForo developer
Staff member
#4
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.
 

Chris D

XenForo developer
Staff member
#6
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()
 

Chris D

XenForo developer
Staff member
#8
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!
 
R

ragtek

Guest
#10
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)