How to get the current route in actionIndex of ControllerPublic?

Scharesoft

Active member
I'm creating an addon for our forum and there I need the current route.

I created a new area with the url "tes". There will be sub areas like tes/skyrim or tes/oblivion. Now I need this route (skyrim or oblivion) in my actionIndex of the ControllerPublic php file.

Route/Prefix file:
PHP:
class TESPortalGameInformation_Route_Prefix_Game implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $controller = 'TESPortalGameInformation_ControllerPublic_Game';

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

ControllerPublic file
PHP:
class TESPortalGameInformation_ControllerPublic_Game extends XenForo_ControllerPublic_Abstract
{
    public function actionIndex()
    {    
         $params = array( ... );
         return $this->responseView('TESPortalGameInformation_ViewPublic_Game', 'tesportal_game_info', $params);
    }
}
It would be possible to create a new actionXYZ for each route, but I think it's better to handle it in the actionIndex.

How to get the current route? Many thanks in advance!
 
Last edited:
Off the top of my head...

PHP:
class TESPortalGameInformation_Route_Prefix_Game implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $controller = 'TESPortalGameInformation_ControllerPublic_Game';

        $path = explode('/', $router->getRoutePath($request));
        $request->setParam('subArea', $path[0]);

        return $router->getRouteMatch($controller, $router->resolveActionWithStringParam($routePath, $request, 'action'), 'tes');
    }
}

Depending on the route, the sub area you are looking for may be in $path[1], you will have to check for this.

PHP:
class TESPortalGameInformation_ControllerPublic_Game extends XenForo_ControllerPublic_Abstract
{
    public function actionIndex()
    {  
         $subArea = $this->_input->filterSingle('subArea', XenForo_Input::STRING);

         $params = array( ... );
         return $this->responseView('TESPortalGameInformation_ViewPublic_Game', 'tesportal_game_info', $params);
    }
}
 
Great, thanks for the help :) It's working after checking the size of the path array and get the last element:

PHP:
class TESPortalGameInformation_Route_Prefix_Game implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $controller = 'TESPortalGameInformation_ControllerPublic_Game';

        $path = explode('/', $router->getRoutePath($request));
        if(isset($path[1])) {
                $request->setParam('subArea', $path[1]);
        }

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

PHP:
class TESPortalGameInformation_ControllerPublic_Game extends XenForo_ControllerPublic_Abstract
{
    public function actionIndex()
    {
        $game = $this->_input->filterSingle('subArea', XenForo_Input::STRING);

        $params = array( ... );

        return $this->responseView('TESPortalGameInformation_ViewPublic_Game', 'tesportal_game_info', $params);
    }
}
 
Last edited:
Back
Top Bottom