AndyB
Well-known member
I'm creating a XF2 add-on called Banner and I would like to pass a variable called $banners into the Advertising HTML like this:
My PHP code is the following:
My code event listener:
My PHP code is the following:
PHP:
<?php
namespace Andy\Banner;
class Listener
{
public static function appPubRenderPage(
\XF\Pub\App $app,
array &$params,
\XF\Mvc\Reply\AbstractReply $reply,
\XF\Mvc\Renderer\AbstractRenderer $renderer
)
{
// 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 *
FROM xf_banner
ORDER BY RAND()
LIMIT ?
", $limit);
// update params
$params['banners'] = $banners;
}
}
My code event listener: