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

How would I extend a Route Prefix with Extra Params?

Discussion in 'XenForo Development Discussions' started by Jaxel, Nov 6, 2011.

  1. Jaxel

    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.
     
  2. Jaxel

    Jaxel Well-Known Member

  3. Fuhrmann

    Fuhrmann Well-Known Member

    How are you passing the 'format' to the extraParams?
     
  4. Lawrence

    Lawrence Well-Known Member

    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
            );
    
     
    Fuhrmann likes this.
  5. Jaxel

    Jaxel Well-Known Member

    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?
     
  6. Jaxel

    Jaxel Well-Known Member

    Okay... I figured it out... I passed the $_input to the $thread data and used that in my route extension.
     

Share This Page