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

BuildLink

Discussion in 'XenForo Development Discussions' started by Daniel Hood, Aug 19, 2013.

  1. Daniel Hood

    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.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    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;
        }
     
    euantor, Marcus and Daniel Hood like this.
  3. Daniel Hood

    Daniel Hood Well-Known Member

    Ahh, thanks. Appreciate it.
     
  4. silence

    silence Well-Known Member

    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($routePathZend_Controller_Request_Http $requestXenForo_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);
        }
    }
     
  5. silence

    silence Well-Known Member

    Bump? Bump.
     
  6. Daniel Hood

    Daniel Hood Well-Known Member

    Did you flip "Use class to build link?" to never on this page? yourboard/admin.php?route-prefixes/add
     
  7. silence

    silence Well-Known Member

    It wasn't set to that, but I changed it and it's still trying to call an action based on what comes after the route.
     

Share This Page