1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trailing Slash?

Discussion in 'XenForo Development Discussions' started by woodenlegacy, Jun 14, 2016.

  1. woodenlegacy

    woodenlegacy Member

    Hey everyone, so im making a page that loads in stats for users, and everything works until you look something up without a /.
    For example,
    http://localhost/forums/stats/user <-- Doesn't work
    http://localhost/forums/stats/user/ <-- Works

    So how would I go about adding a trailing slash for links that dont have one?
    Heres my route :

    PHP:
        public function match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            
    $action $router->resolveActionWithStringParam($routePath$request'username');
            
    $action $router->resolveActionAsPageNumber($action$request);
           
            
    $actions explode('/'$action);
            switch (
    $actions[0])
            {
                case 
    'search':    $controller 'Search';        break;
                default:            
    $controller '';
            }
           
            return 
    $router->getRouteMatch('bdStats_ControllerPublic_Stats'$controller$action'stats');
        }
        public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
        {
                return 
    XenForo_Link::buildBasicLinkWithStringParam($outputPrefix$action$extension$data'username');
        }
     
  2. Chris D

    Chris D XenForo Developer Staff Member

  3. woodenlegacy

    woodenlegacy Member

    Thanks for the quick reply man! Ive tried using the code like this, and cant seem to get it to work, what does the "2" in "$routePath, 2" represent?
    PHP:
            $parts explode('/'$routePath2);
            if (isset(
    $parts[0]))
            {
                if (
    $parts[0] == 'stats')
                {
                    if (
    utf8_substr($parts[1], -1) != '/')
                    {
                        
    $parts[1] .= '/';
                    }

                    
    $routePath implode('/'$parts);
                }
            }
            
    $action $router->resolveActionWithStringParam($routePath$request'username');
            
    $action $router->resolveActionAsPageNumber($action$request);
            return 
    $router->getRouteMatch('bdStats_ControllerPublic_Stats'$action$routePath'stats');
     
  4. tobbe

    tobbe New Member

    It sets a limit on explode(). Meaning $parts[0] will contain everything before the first "/" and $parts[1] will contain the rest.
    http://php.net/manual/en/function.explode.php
     
  5. woodenlegacy

    woodenlegacy Member

    Does the way I have it in my route look correct ? I apologize for my lack of understanding, http://localhost/forums/stats/user/ works and http://localhost/forums/stats/user doesn't, Im trying to force a trailing slash onto it, just cant seem to get it to work, again sorry for my lack of understanding, and thank you for your help an time.
     

Share This Page