AndyB
Well-known member
In my Banner add-on, I would like to pass a variable from PHP code to the PAGE_CONTAINER template.
The goal is to display a random image in the header with a different image being display upon each page load.
For example I pass from PHP a variable to the forum_list template using this code:
Thank you.
The goal is to display a random image in the header with a different image being display upon each page load.
For example I pass from PHP a variable to the forum_list template using this code:
PHP:
<?php
namespace Andy\Banner\XF\Pub\Controller;
use XF\Mvc\ParameterBag;
class Forum extends XFCP_Forum
{
public function actionList(ParameterBag $params)
{
//########################################
// show banner in forum_list
//########################################
// get parent
$parent = parent::actionList($params);
// get visitor
$visitor = \XF::visitor();
// check for user group permission
if (!$visitor->hasPermission('banner', 'view_forum_list_top') AND !$visitor->hasPermission('banner', 'view_forum_list_bottom'))
{
return $parent;
}
// get options
$options = \XF::options();
// get options from Admin CP -> Options -> Banner -> Limit
$limit = $options->bannerLimit;
// get db
$db = \XF::db();
// run query
$banners = $db->fetchAll("
SELECT image_url,
link,
target
FROM xf_andy_banner
WHERE active = 1
ORDER BY RAND()
LIMIT ?
", $limit);
// return if no banners
if (empty($banners))
{
return $parent;
}
$parent->setParams([
'banners' => $banners
]);
return $parent;
}
Thank you.
Last edited: