Having an odd issue with routes in my addon

Dannymh

Active member
Hi,

I am writing an addon which uses a route for mvp, my route file looks like

PHP:
<?php

class Silvertails_Mvp_Route_Prefix_Mvp implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithIntegerParam($routePath, $request, 'id');
        return $router->getRouteMatch('Silvertails_Mvp_ControllerPublic_App', $action, 'mvp');
    }
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'id', 'title');
    }
}

I then have a few links within my templates that get built as you click through the various depths of the addon, these links look like

PHP:
<a href="{xen:link 'mvp/games', {xen:array 'id={$season.id}', 'title={$season.season_name}'}}">{xen:phrase silvertails_mvp_view} {xen:phrase silvertails_mvp_games}</a>

<a href="{xen:link 'mvp/leaders', {xen:array 'id={$game.id}', 'title={$game.round_name}'}}">{xen:phrase silvertails_mvp_view} {xen:phrase silvertails_mvp_votes}</a>

If I click on the first link it takes me to the correct controller which is Silvertails_Mvp_ControllerPublic_App and calls the action action of actionGames this then goes through my route prefix correctly and i can access both title and id

if I then got through the second link again it calls the correct controller and correct action, however the route doesnt seem to work properly and only ID is available but title isn't.

If I do a print_r within by buildlink it for $data it comes up as blank.

I can't see what would stop this working from one function to the next as they are identical in the way they do things and only differ in the model and template they call.

Any ideas?
 
Actually whilst that works, it is less than ideal for what I am trying to do as it gives the addition title= at the end when ideally that wouldn't exist

So if anyone has any thoughts I would love to hear them
 
I'm not sure what you mean by forcing in by using $extraParams, anyway I would do something like the following:

Code:
  public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
{
if(!empty($extraParams["title"]))$data["title"]=$extraParams["title"];
return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, "", $data, 'id', 'title');
}
 
cheers I will give it a try.

Also in my route match I added
Code:
$action = $router->resolveActionWithStringParam($routePath, $request, 'title');

which seems to have also fixed it
 
Back
Top Bottom