BuildLink

Daniel Hood

Well-known member
I have my route split into two sections with this method:
PHP:
$action = $router->getSubComponentAction($this->_subComponents, $routePath, $request, $controller);

which works fine, my single route handles {addon}/{section}/{action} through a single route class and works fine as far as going through the right controller.

I'm attempting to use:
{xen:adminlink '{addon}/{section}/{action}', $data}

which I feel should produce the url: {addon}/{section}/{title}.{id}/{action} but it instead products {addon}/{title}.{id}/{section}/{action} which doesn't feed through the right controller.

My build link function for my route is this (mostly because I don't have much experience with routes and this is the thing I've got working):

PHP:
public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
                return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'product_id', 'title');
    }

Let me know if it's unclear what I'm trying to do.
 
The buildLink function should look something like this. Notice, it uses a different function to build a link using sub components:

PHP:
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        $link = XenForo_Link::buildSubComponentLink($this->_subComponents, $outputPrefix, $action, $extension, $data);
        if (!$link)
        {
            $link = XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'product_id', 'title');
        }
        return $link;
    }
 
The buildLink function should look something like this. Notice, it uses a different function to build a link using sub components:

PHP:
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        $link = XenForo_Link::buildSubComponentLink($this->_subComponents, $outputPrefix, $action, $extension, $data);
        if (!$link)
        {
            $link = XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'product_id', 'title');
        }
        return $link;
    }
Ok I'm hijacking this thread since I'm having a somewhat similar issue:
Basically I want to use the url site.com/kinectsupport/players/{username}/ but it is telling me that it attempted to find the action {username} and failed which isn't what I want it to do. I don't think the issue is with 'getSubComponentAction' since browsing through the XF code tells me that it's grabbing the 'stringId' properly and resolving it properly as well. My ControllerPublic is getting the input, however trying to dump it inside it's controllerpublic prints nothing. Dumping it in the route controller prints the exact parameter! What should I do since I'm more stumped then... well a stump.

Route Prefix:
PHP:
<?php

class XenoGamers_KinectSupport_Route_Prefix_KinectSupport implements XenForo_Route_Interface
{
    protected $_subComponents = array(
        'busty' => array(
            'controller' => 'XenoGamers_KinectSupport_ControllerPublic_Busty_Index'
        ),
        'players' => array(
            'controller' => 'XenoGamers_KinectSupport_ControllerPublic_Players_Index',
            'stringId' => 'username'
        )
    );

    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $controller = 'XenoGamers_KinectSupport_ControllerPublic_Index';
        $action = $router->getSubComponentAction($this->_subComponents, $routePath, $request, $controller);

        return $router->getRouteMatch($controller, $action, 'kinect');
    }

    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        // anything I echo here, it won't print out!

        return XenForo_Link::buildSubComponentLink($this->_subComponents, $outputPrefix, $action, $extension, $data);
    }
}
 
Top Bottom