Passing parameters to links

euantor

Well-known member
I'm trying to create an extension for the ACP that requires a URL such as the following:

Code:
item/edit

I have the following in my ItemController:

Code:
  public function actionEdit()
  {
    if (!$this->hasAdminPermission('xd_items_mod_edit')) {
      return $this->responseNoPermission();
    }

    $itemId = $this->_input->filterSingle('item_id', XenForo_Input::UINT);

    var_dump($itemId);
  }

My index template has the following code:

Code:
  <ol class="FilterList">
     <xen:foreach loop="$items" key="$itemId" value="$item">
       <xen:listitem id="{$item.id}"
         href="{xen:if $canEditItems, {xen:adminlink 'items/edit', $item}}"
         label="{$item.title}"
         snippet="{$item.blurb}"
         delete="{xen:adminlink 'items/delete', $item}"
         deletehint="{xen:phrase xd_items_mod_delete}">
       </xen:listitem>
     </xen:foreach>
   </ol>

My Route prefix class has the following code:

Code:
<?php

class Test_Route_PrefixAdmin_Items implements XenForo_Route_Interface, XenForo_Route_BuilderInterface
{
  /**
  * Method to be called when attempting to match this rule against a routing path.
  * Should return false if no matching happened or a {@link XenForo_RouteMatch} if
  * some level of matching happened. If no {@link XenForo_RouteMatch::$controllerName}
  * is returned, the {@link XenForo_Router} will continue to the next rule.
  *
  * @param string  $routePath Routing path
  * @param Zend_Controller_Request_Http $request  Request object
  * @param XenForo_Router  $router  Router that routing is done within
  *
  * @return false|XenForo_RouteMatch
  */
  public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
  {
  $action = $router->resolveActionWithIntegerParam($routePath, $request, 'item_id');

  return $router->getRouteMatch('Test_ControllerAdmin_Item', $action, 'items');
  }

  /**
  * Method to build a link to the specified page/action with the provided
  * data and params.
  *
  * @see XenForo_Route_BuilderInterface
  */
  public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
  {
  return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'item_id');
  }
}

However, when I hit the edit route, $itemId is always 0. Am missing something? Do I need to do something else with the route?
 
Whoops, found the issue. The field int eh database is simply "id", not "item_id". Therefore "item_id" isn't available as a parameter. Now I feel stupid...
 
Top Bottom