Admin Pages

XenForo has default functions for handling sub-componented routes.

Here's how I (and XenForo core) would do it:

PHP:
<?php

class Teamspeak_Route_PrefixAdmin_Teamspeak implements XenForo_Route_Interface
{
    protected $_subComponents = array(
        'information' => array(
            'controller' => 'Teamspeak_ControllerAdmin_Information'
        ),
        'users' => array(
            'controller' => 'Teamspeak_ControllerAdmin_Users',
            'intId' => 'user_id',
            'title' => 'username'
        )
    );
       
    /**
    * Match a specific route for an already matched prefix.
    *
    * @see XenForo_Route_Interface::match()
    */
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $controller = 'Teamspeak_ControllerAdmin_Index';
        $action = $router->getSubComponentAction($this->_subComponents, $routePath, $request, $controller);

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

    /**
    * 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::buildSubComponentLink($this->_subComponents, $outputPrefix, $action, $extension, $data);
    }
}
 
Top Bottom