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

Jaxel's Method for Creating A Route Controller

The "proper" way to construct complicated route controllers...

  1. Jaxel

    Jaxel Well-Known Member

    Jaxel submitted a new resource:

    Creating A Neater Route Controller (version 2.0) - The "proper" way to construct complicated route controllers...

    Read more about this resource...
     
  2. Jaxel

    Jaxel Well-Known Member

    Okay, guide is done!
     
  3. Jaxel

    Jaxel Well-Known Member

  4. morpheus

    morpheus Member

    Thanks for this guide Jaxel! Being new to developing xenForo mods and PHP itself this explains a lot!
     
  5. Jaxel

    Jaxel Well-Known Member

    I realize now though that the guide I put together only works if your data actions have integers in them. If you're doing PURE string data, you may have issues. I came into this issue with my XenMedio mod; almost all the data types use number IDs... except for keyword pages. Keyword pages use string data only... I managed a workaround using the following as my match:

    Code:
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithIntegerParam($routePath, $request, 'action_id');
        $action = $router->resolveActionAsPageNumber($action, $request);
       
        $actions = explode('/', $action);
       
        switch ($actions[0])
        {
            case 'admin':            $controller = '_Admin';                break;
            case 'category':        $controller = '_Category';            break;
            case 'comment':            $controller = '_Comment';            break;
            case 'keyword':            $controller = '_Keyword';            break;
            case 'media':            $controller = '_Media';                break;
            case 'playlist':        $controller = '_Playlist';            break;
            case 'user':            $controller = '_User';                break;
            case 'service':            $controller = '_Service';            break;
            default:                $controller = '';
        }
       
        if (!empty($actions[1]) && $actions[1] == 'keyword')
        {
            $controller = '_Keyword';
            $action = $router->resolveActionWithStringParam($routePath, $request, 'string_id');
        }
       
        return $router->getRouteMatch('EWRmedio_ControllerPublic_Media'.$controller, $action, 'media');
    }
    
     
    Brad L and tyteen4a03 like this.
  6. Matthew Hawley

    Matthew Hawley Well-Known Member

    So...what do we name the PHP files?
     
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    The names of the files should correspond to the classes. Replace _ with / and add .php at the end.
     

Share This Page