1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

[Library] Set your own Route/Controller as Homepage

Discussion in 'Development Tutorials [Archive]' started by Shadab, Jan 8, 2011.

  1. Shadab

    Shadab Well-Known Member

    Just a quick addon/library I put together for shifting the forum listing to /forum/ and setting the homepage to be handled by your controller's index action.

    These instructions are for the next release of XenForo (Beta 6), which will hopefully require no patch for this to work. Patches for Beta 5 will be posted shortly in the second post below.

    1. Download the attached zip file.
    2. Extract and upload the contents inside your /library/ directory.
    3. There's no step 3. :)


    There's only one static method which you need to call. The first argument (type: Zend_Config) is the configuration data you need to pass; and the second argument (type: array) is the dependency data supplied by init_dependencies.

    GeekPoint_CustomIndex_Helper::setDefaultRoute($config, $data);



    This is the route prefix which you want to set as the default. Suppose you set the "foo" route-prefix as default, any links generated for "foo" or "foo/index" will now point to the homepage "/".​


    This is the controller class which will handle the homepage. Specifically, the actionIndex() method in your controller will be responsible for generating the homepage.​


    [Optional] The major section-name, used when generating the route-match for homepage.​


    [Optional] The minor section-name, used when generating the route-match for homepage.​


    [Optional] Parameters that will be added to the request object during the routing process. This enables you to set any content which depends upon a request parameter to be present, as your homepage. For example: node "Pages", or Threads (yes, threads! But for heaven's sake don't do that.)


    Create a new event-listener for init_dependencies. Then in your callback method, just set the configuration options, and call the helper. That's it. Some examples are given below, starting with the code for setting "Recent Activity" as your homepage...

    public static function initDependencies(XenForo_Dependencies_Abstract $dependencies, array $data)
        if (!
    $dependencies instanceof XenForo_Dependencies_Public)

    $config = new Zend_Config(array(
    'routePrefix'     => 'recent-activity',
    'controllerClass' => 'XenForo_ControllerPublic_RecentActivity',


    Configuration for setting the portal page as homepage...

    (No other changes required.)

        $config = new Zend_Config(array(
    'routePrefix'     => 'portal',
    'controllerClass' => 'EWRporta_ControllerPublic_Portal',
    'majorSection'    => 'portal'

    Configuration for setting a node page as the homepage.

    (Replace "lectus-pretium-consequat" with your node name. Any changes that you make to the page name via Admin Panel need to be reflected in this config array.)

        $config = new Zend_Config(array(
    'routePrefix'     => 'pages',
    'controllerClass' => 'XenForo_ControllerPublic_Page',
    'params'          => array('node_name' => 'lectus-pretium-consequat'),


    Since this addon(?) is released under the MIT License, you are free to include and use this in your own addons & products. It would be nice if you leave the directory structure & the files included therein, unmodified; but it's not a requirement.

    The complete license text is available in the LICENSE file inside the release package.

    Related Threads

    Attached Files:

    8thos, Arty, Fuhrmann and 14 others like this.
  2. Shadab

    Shadab Well-Known Member

    Patches for XenForo Beta 5 (only):

    (1) /library/XenForo/Link.php

    Find: (line 377)
            $handler = new $class();
    Replace with:
            $class XenForo_Application::resolveDynamicClass($class'route_prefix');
    $handler = new $class();

    (2) /library/XenForo/Link.php

    Find: (line 272-275)
            if ($prefix === 'index' && $action === '' && $extension === '')
    Remove it.
    Vincent likes this.
  3. Jeremy

    Jeremy Well-Known Member

    For the record... this is sooooooo much easier than my attempted method. :)
  4. Jeremy

    Jeremy Well-Known Member

    Random question. If someone were to-do this, how is the forum index made available?
  5. Shadab

    Shadab Well-Known Member

    The forum index gets moved to "/forum/".
    Existing links to the forum index, eg. {xen:link index} will also point to this new url.
  6. Brogan

    Brogan XenForo Moderator Staff Member

    Great work Shadab!

    Just to be clear, if my existing URL is http://xenforo.com/community/forums/announcements/
    After installing this it will be http://xenforo.com/community/forum/announcements/

    So /forums will change to /forum, is that correct?

    And if I currently have a page like so: http://xenforo.com/community/pages/home/
    I can now set it to be http://xenforo.com/home/

    Or have I misunderstood?
  7. Jaxel

    Jaxel Well-Known Member

  8. Brogan

    Brogan XenForo Moderator Staff Member

  9. Jaxel

    Jaxel Well-Known Member

  10. Brogan

    Brogan XenForo Moderator Staff Member

  11. Jaxel

    Jaxel Well-Known Member

    No... it doesn't do that.

    The reason why it has /forum/ vs /forums/ is because /forums/ already is it's own route prefix. Rather than interfering with that route prefix and forcing tons upon tons of more code which could bog things down, he simply created a new route for the index mapped to /forum/.

    Either way, I think this feature should be built into XenForo... it should not be a separate mod.
    Onimua and Shadab like this.
  12. Brogan

    Brogan XenForo Moderator Staff Member

    I'm not sure I agree with how this works.

    The URL structure changes from the forum home to individual forums.
    Forums and threads are part of the /forum route so that shouldn't be removed.

    That would be similar to clicking on Members and then an individual member and the /members portion of the URL being removed.
  13. Jeremy

    Jeremy Well-Known Member

    I just clicked on basically a vanilla install, installed in my root (without this mod), and the link was: localhost/xen/index.php?forums/forum-name.1/. There was no forum/forums/. It happens here because XenForo is installed under a sub-directory. Without rewrites it'd be community/index.php?forums/forum-name.1/.

    What this does is redefine the route prefix: index.php?index (or nothing) to be index.php?forum/ because it redefines the action of the index route to be the router & action that you set it to be.
  14. Shadab

    Shadab Well-Known Member

    Quick Comparison of route prefixes, used for matching:

    Stock XenForo:
    • homepage: /index/ (points to the forum home)
    • individual forums: /forums/
    • individual threads: /threads/
    • individual pages: /pages/
    Shifting forum home to its separate route-prefix:
    • homepage: /index/ (points to your own controller)
    • forum home: /forum/
    • individual forums: /forums/
    • individual threads: /threads/
    • individual pages: /pages/
    Jaxel is right in that it's more work for me to reuse the /forums/ route prefix, because it already is used for displaying individual forums and sub-forums. So shifting the forum home to a separate route prefix (/forum/) is easier.
  15. Brogan

    Brogan XenForo Moderator Staff Member

    Thanks for the comparison Shadab.

    Is the forum home: /forum/ in the second list related to the install path?
    So here for example it would still be /community/ using your mod?
  16. Shadab

    Shadab Well-Known Member

    All the given paths/prefixes are relative to your installation directory.
    Nothing gets shifted outside your install path.
  17. Brogan

    Brogan XenForo Moderator Staff Member

    Many thanks for the clarification.

    I'll be installing this later on my local install to test it out.

    Can't wait to migrate now :D
    Shadab likes this.
  18. ddmmh

    ddmmh Well-Known Member

    Is this method better to use then .htaccess re-direct which im using now? cheers
  19. Shadab

    Shadab Well-Known Member

    That depends on where you've got xenforo installed.
    I'd suggest using this lib if you have everything in your domain root.
    ddmmh likes this.
  20. yavuz

    yavuz Well-Known Member

    What it we have a wordpres blog lets say root/blog directory. How do we set up it as home page ? I was looking forward to this and give it a try.
    Digital Doctor likes this.

Share This Page