How to create a "double intParams" in a route ?

SNK

Member
Hello,

Firstly, I'm French and sorry for my bad english.
I want to create a route with two integer, exemple :
Code:
https://mysite.com/module/first_id/users/second_id/action

But I can't do this, for the moment I have :
Code:
https://mysite.com/module/users/first_id/second_id/action

My xenForo's Route :
PHP:
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $components = explode('/', $routePath);
        $subPrefix = strtolower(array_shift($components));
        $subSplits = explode('.', $subPrefix);

        $controllerName = '';
        $action = '';
        $intParams = '';
        $strParams = '';
        $slice = false;

        switch ($subPrefix)
        {
            case 'add':
                $controllerName = '_Add';
                $slice = true;
            break;

            case 'users':
                $controllerName = '_Users';
                $slice = true;
                $request->setParam('first_id', array_shift($components));
                $request->setParam('second_id', array_shift($components));
            break;

            default :
                $controllerName = '_Index';
                $intParams = 'first_id';
        }

        $routePathAction = ($slice ? implode('/', array_slice($components, 0, 2)) : $routePath).'/';
        $routePathAction = str_replace('//', '/', $routePathAction);

        if ($strParams)
        {
            $action = $router->resolveActionWithStringParam($routePathAction, $request, $strParams);
        }
        else
        {
            $action = $router->resolveActionWithIntegerParam($routePathAction, $request, $intParams);
        }

        $action = $router->resolveActionAsPageNumber($action, $request);
        return $router->getRouteMatch('MyModule_ControllerPublic'.$controllerName, $action, 'module_name', $routePath);
    }

    /**
     * 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)
    {
        $components = explode('/', $action);
        $subPrefix = strtolower(array_shift($components));

        $intParams = '';
        $strParams = '';
        $title = '';
        $slice = false;

        switch ($subPrefix)
        {
            case 'add':
                $slice = true;
            break;

            case 'users':
                $intParams = 'second_id';
                $slice = true;
            break;
            default:            $intParams = 'first_id';        $title = 'title';
        }

        if ($slice)
        {
            $outputPrefix .= '/'.$subPrefix;
            $action = implode('/', $components);
        }

        $action = XenForo_Link::getPageNumberAsAction($action, $extraParams);

        if ($strParams)
        {
            return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $data, $strParams);
        }
        else
        {
            return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, $intParams, $title);
        }
    }

Of course, I have replaced the values with my personnal values, it just the name of XX_id who change.

---

I know it is possible, like "http://8wayrun.com/rankings/thermidor.2162/user/1" :)

Thanks,
Benjamin.
 
You're using my old routing guide... which I stopped following over 2 years ago... Here is the new guide:

https://xenforo.com/community/resources/jaxels-method-for-creating-a-route-controller.1637/
I've read this, but the part "need more data" is not very explicit for me.
The following url "module/creer" is not functional with your method.
Code:

PHP:
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithStringParam($routePath, $request, 'string_id');
        $action = $router->resolveActionWithIntegerParam($routePath, $request, 'action_id');

        $actions = explode('/', $action);

        switch ($actions[0])
        {
            case 'creer':    $controller = '_Creation'; $action = 'creer';       break;
            case 'users':
            $controller = '_Users';

            if (!empty($actions[1]) && intval($actions[1]))
            {
                // + action_id
                $request->setParam('user_id', intval($actions[1]));
                $action = 'users';
            }

            break;
            case 'index':        $controller = '_Index';            break;
            default:            $controller = '_Index';
        }

        $action = $router->resolveActionAsPageNumber($action, $request);
        return $router->getRouteMatch('MyModule_ControllerPublic'.$controller, $action, 'module_name', $routePath);
    }

    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        $actions = explode('/', $action);

        switch ($actions[0])
        {
            case 'creer':        $intParams = '';        $strParams = '';            break;
            case 'users':        $intParams = 'user_id';        $strParams = '';        break;
            default:            $intParams = 'action_id';                $strParams = 'title';                    break;
        }

        $action = XenForo_Link::getPageNumberAsAction($action, $extraParams);

        if ($intParams)
        {
            return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, $intParams, $strParams);
        }
        else
        {
            return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $data, $strParams);
        }
    }
And
Code:
https://mysite.com/module/users/first_id/second_id/action
is not functional..
Any idea ?
 
Top Bottom