How would I extend a Route Prefix with Extra Params?

Jaxel

Well-known member
Lets say I have an extra param in a URL with "?format=default"... How would I add this to the router? I tried extending the class with a listener... but for some reason, the contents of "$extraParams" is always empty in my extended class. It doesn't even have the stuff its supposed to have. How do I do this?

Code:
<?php
 
class EWRporta_Listener_Route
{
    public static function route($class, array &$extend)
    {
        switch ($class)
        {
            case 'XenForo_Route_Prefix_Threads':
                $extend[] = 'EWRporta_Route_Thread';
                break;
        }
    }
}

Code:
<?php
 
class EWRporta_Route_Thread extends XFCP_EWRporta_Route_Thread
{
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        $response = parent::buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, $extraParams);
 
        if (!empty($extraParams['format']))
        {
            $split = explode('#', $response, 2);
            $hash = !empty($split[0]) ? $split[0] : '';
            return $split[0] . '?format=' . $extraParams['format'] . $hash;
        }
 
        return $response;
    }
}

The contents of $extraParam is empty if I print_r it out.
 
Code:
    class XenFx_AdManager_Route_Prefix_Clicks implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithStringParam($routePath, $request, 'banner');
        return $router->getRouteMatch('XenFx_AdManager_ControllerPublic_Clicks', $action, 'amclk');
    }
 
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        $extraParams['url'] = $data['url'];
        return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $data, 'banner_id', $extraParams);
    }
}

The above is what I use to pass the banner id and URL of a clicked ad to the controller to track the data for my Ad Manager. I'm not sure if it is the right way or not but it works. The click is saved and the user who clicked it is re-directed to the url associated with the ad.

The controller for the click grabs the URL the normal way:
Code:
        $bannerId = $this->_input->filterSingle('banner', XenForo_Input::UINT);
        $bannerURL = $this->_input->filterSingle('url', XenForo_Input::STRING);
 
        if ($bannerId)
        {
           increment the click count for that banner...
        }
 
        return $this->responseRedirect(
            XenForo_ControllerResponse_Redirect::SUCCESS,
            $redirectTarget = $bannerURL
        );
 
Lawrence, thats not really an option, since thats not extending the EXISTING thread router.

I think when it comes down to it, the question is... Can I get $_input inside of a Route controller?
 
Okay... I figured it out... I passed the $_input to the $thread data and used that in my route extension.
 
Top Bottom