Registering variable for use on index?

subtato

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.
Thanks!
 
Maybe you're looking for XenForo_Application::get/set, if you need the equivalent of a "global" variable?

PHP:
// early in the code
XenForo_Application::set('ezirc_channel', $channel);

// 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.
 
edit2: FIGURED IT OUT!
Thanks to calorie(?) who had the most liked mod .. worked perfect looking at someone elses' code :)
Maybe you're looking for XenForo_Application::get/set, if you need the equivalent of a "global" variable?

PHP:
// early in the code
XenForo_Application::set('ezirc_channel', $channel);

// 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.
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:
PHP:
<?php
class ezirc_Public_StatsBlock
{
	public static function getChannel($fc, &$controllerResponse, &$viewRenderer, &$controllerParams)
	{
		$options = XenForo_Application::get('options');
		if($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");
			if(count($channel) > 0)
			{
				XenForo_Application::set('ezirc', $channel);
				$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. :/
 
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).
 
Top Bottom