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

Controller, router and me.

Discussion in 'XenForo Development Discussions' started by dmnkhhn, Oct 30, 2010.

  1. dmnkhhn

    dmnkhhn Active Member

    I have asked a similar question before but I still haven't found a good solution so far.

    For my add-on I am currently using 2 PublicControllers, each with a separate route.

    The url structure looks like this:

    myxenforo.com/bookshelf (index, with all bookshelves)
    myxenforo.com/bookshelf/1 (bookshelf, id1)
    myxenforo.com/bookshelf/2 (bookshelf, id1)

    myxenforo.com/book (index, with all books)
    myxenforo.com/book/1 (book, id1)
    myxenforo.com/book/2 (book, id1)

    That's totally fine (for now) but I have one big problem: There is no way to display all bookshelves by user X.
    This would require an url structure like myxenforo.com/bookshelf/member/1 (or similar)

    With my current setup, it asks me for an action 'Member1' when want to open a link like this.

    I am implementing the XenForo_Route_Interface, this is my method:
        public function match($routePathZend_Controller_Request_Http $requestXenForo_Router $router) {
    $action $router->resolveActionWithIntegerParam($routePath$request'book_id');


    What do I have to change to be able to use


    Thanks for your help. :)
    Jeremy likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    The resolveActionWithIntegerParam method (and the converse version for link building) is really just a helper method. If you want to do something more complex (which this would fit under), you will have to do more low level structural parsing. (There are a few places we have done this, but usually it's just a pain.)

    Though as an aside, what about members/1/bookshelf?
  3. dmnkhhn

    dmnkhhn Active Member

    Thanks Mike, I will take a closer look at the XenForo code. :)

    members/1/bookshelf sounds good, too. Can this be done without breaking the default routing that handles the member stuff?
  4. Mike

    Mike XenForo Developer Staff Member

    Yeah, it's really setup for it already. You just need to use load_class_controller to extend the Member controller for your action.
  5. dmnkhhn

    dmnkhhn Active Member

    Thanks Mike, it's working like a charm. :)

    Here's what I did:
    I created a new code event listener that listens to 'load_class_controller'.

    The execution callback is: Doh_Books_Listeners_LoadClassController::loadClassListener

    My listener (library/Doh/Books/Listeners/LoadClassController.php) looks like this:
    class Doh_Books_Listeners_LoadClassController
         * @static
         * @param  $class
         * @param  $extend
         * @return void
    public static function loadClassListener($class, &$extend)
            if (
    $class == 'XenForo_ControllerPublic_Member')
    $extend[] = 'Doh_Books_ControllerPublic_MemberBook';

    As far as I can see, I need the separate controller for this because otherwise it is going to overwrite the Member controller with all actions from my main controller.
    maitandat1507 likes this.
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    I'm sorry to be posting, but I actually laughed at the title of this thread. :) +1!

Share This Page