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

Xenforo option, return array

Discussion in 'XenForo Development Discussions' started by Zephyr, Oct 16, 2012.

  1. Zephyr

    Zephyr Well-Known Member

    Hello, I would like to know how to return an array of values ​​with options XenForo please.

    Is there a basic code please?


    Thank :)
  2. Jeremy P

    Jeremy P Well-Known Member

    You want to take a comma separated list from options and split the values into an array?

    $options XenForo_Application::get('options');
    $option $options->yourOptionId// this will get the value of your option, something like 1,10,27
    $option explode(','$option);
    // $option would now be: array('1', '10', '27');
    You could also set the option itself to be an array instead of a string by default, but I would imagine that would require an validation callback to take the input and put it into an array.
    luutruong, Zephyr and Jake Bunce like this.
  3. Zephyr

    Zephyr Well-Known Member

    Thanks Jeremy :)
  4. Zephyr

    Zephyr Well-Known Member

    Hello, I have this:


    Code :

    abstract class XenCrea_ColorPicker_Option_ArrayDeClassEtId
        public static function ColorList($preparedOption, $canEdit)
            $value = $preparedOption['option_value'];
            $options = XenForo_Application::get('ffff');
            $option = $options->yourOptionId; // this will get the value of your option, something like 1,10,27
            $option = explode(',', $option);
            // $option would now be: array('1', '10', '27');
            return $option;
    I have an error :


    I can not find what's wrong, I'm not accustomed to using the callback returns.
    Can you help me please ? :)
  5. Lawrence

    Lawrence Well-Known Member

    If I understand what you want to do, you have to set the Edit Format to PHP Callback.
    In the Format Parameters place your callback there: XenCrea_ColorPicker_Option_ArrayDeClassEtId::renderColorList (I changed the name of the function to reflect what it will do)

    Your Format Parameters callback will take care of rendering the options and should look something like this:

        class XenCrea_ColorPicker_Option_ArrayDeClassEtId
            public static function 
    renderColorList(XenForo_View $view$fieldPrefix, array $preparedOption$canEdit)
    $preparedOption['formatParams'] = XenForo_Model::create('XenCrea_ColorPicker_Model_ColorOptions')->getColors(

Share This Page