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

Registering variable for use on index?

Discussion in 'XenForo Development Discussions' started by Facepalmx2, Oct 10, 2010.

  1. Facepalmx2

    Facepalmx2 Active Member

    Hey guys.

    I'm trying to register a variable called '$channel' on /index.php (the forum list) so I can use it with a stats block. Would anyone have any idea how to do such a thing? (Only thing stopping me from finishing a product :p)

    If anyone could help, that'd be great.
  2. Facepalmx2

    Facepalmx2 Active Member

    Bump - Anyone? :)
  3. Indigo

    Indigo Active Member

    Maybe you're looking for XenForo_Application::get/set, if you need the equivalent of a "global" variable?

    // early in the code

    // someplace else, later on...
    $channel XenForo_Application::get('ezirc_channel');
    Refer to http://framework.zend.com/manual/en/zend.registry.using.html - XF's Application class extends Zend_Registry.

    For making it available to a template, extend the relevant controller (or view) and modify the relevant method's return value to add the variable to its $params property. For adding something to the container, it looks like you'll want to set up an event listener for front_controller_pre_view.
    Fuhrmann and Facepalmx2 like this.
  4. Facepalmx2

    Facepalmx2 Active Member

    edit2: FIGURED IT OUT!
    Thanks to calorie(?) who had the most liked mod .. worked perfect looking at someone elses' code :)
    Thank you, first response that's made sense :D Will try in just a moment

    Already tried the set() thing btw, I just figured it set into the templates haha.

    Edit; okay so, I got the variable to display on the pages (even though it is not currently limited, just yet...) and I cannot get the data to parse in the templates.

    Here's my code:
    class ezirc_Public_StatsBlock
        public static function 
    getChannel($fc, &$controllerResponse, &$viewRenderer, &$controllerParams)
    $options XenForo_Application::get('options');
    $options->ezirc_active && $controllerParams['majorSection'] == 'forums')
    $db XenForo_Application::get('db');
    $xftp "xf_";
    $channel $db->fetchRow("SELECT * FROM `" $xftp "ezirc_channels` WHERE `stats`='1' LIMIT 1");
    count($channel) > 0)
    $controllerParams['ezirc'] = $channel;
    //print_r($controllerParams); // Print information
    I tried $fc->viewParams['ezirc'] = $channel, no luck, and the provided example (with controllerParams) does not work. I'm clueless as far as integration between event listeners and the templates going together. :/
  5. Indigo

    Indigo Active Member

    Glad you got it figured out. :)

    So I take it you didn't need the variable in the container then? Makes things a bit easier, I guess (haven't personally used container params yet).
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    Try returning controller params.

Share This Page