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.

Page Nav

Discussion in 'Development Tutorials [Archive]' started by Arik, Mar 12, 2011.

  1. Arik

    Arik Well-Known Member

    It's actually the rougher of the two approaches. Have to extend the Controller, too. I just ran through it...I'll attach my code, along with a plugin so you should be able to install it and run, if you want to do that.

    If you want to learn, I'll answer questions. If you just want to use it, it should work.

    Please realize, I'll answer questions, but I'm not releasing a supported mod here. Presently, this works with just this example. I'm just providing some sample code you can adapt to different situations.

    Attached Files:

    glorify and gldtn like this.
  2. gldtn

    gldtn Well-Known Member

    I looked quickly though the code, but have to look at it better when I'm not sleepy.. although the addon installation is telling me to : Please enter a valid callback method.

    I went back and check at the code again and everything seems to be pointing to the right dir, not mis types or anything

    I also tried adding the code event listener manually and it telling me the same thing

    One thing I'm having problem understanding is where the Asp_ prefix coming from?
  3. Arik

    Arik Well-Known Member

    All the XenForo code I write lives under an Asp directory.

    I forgot to include it in the above zip. New zip should have it.
  4. gldtn

    gldtn Well-Known Member

  5. Arik

    Arik Well-Known Member

    That's odd. I got a redirect to the URL I was expecting.

    Are you using my plugin exactly? Did you alter the code anywhere? If you go straight to /bibleoteca, does it work?
  6. gldtn

    gldtn Well-Known Member

    Got it.. I think when I was changing the code from bibleoteca to biblioteca, I must of did something wrong!

    Also in your zip file in the xml you left active="0":
    <listener event_id="navigation_tabs" execute_order="10" callback_class="Asp_Biblioteca_Plugin_Plugin" callback_method="extendNavTabs" active="0" description="Navtab for biblioteca"/>
    So i changed it to 1 to activate it.

    I understand the plugin part, but the I'm not totally sure as to when I should use ControllerPublic and Route, also how do I create the xml file when I'm done with my plugin? Do I just export it?

    Thank you a lot for this!
  7. Arik

    Arik Well-Known Member

    Been a little while since 7th grade Spanish for me. ;)

    I used it for testing, but yeah. I guess I didn't tell you how to link to the page, did I? Actually, with the plugin, both styles of URLs will get you to the same place (with the correct URL!), so you can also use this for a link in the node tree, if you wanted.

    The Route Prefix is first assigned in the admin (when you're in debug mode, you can see that). It's configured to point to the Route Prefix class. The class is responsible for pulling off URL parameters (node name in the case of pages, user id for profile pages, thread id & page id for threads, etc), assigns a few additional variables (this is where it finds out which is the selected tab). The other function in a Route Prefix class is for building the URL.

    So, in the case of this plugin, all it does is listen for a /biblioteca url (see, I'm learning!), assigns the node name, and sends the request off to the Controller.

    All of the actionXXX functions within the Controller are basically like individual .php pages. They work with the model to build the page, then sends everything off to the View layer. The only reason I had to overwrite the controller was because it tries to canonicalize the URL before doing the processing. So, I had to stop it from redirecting you from /biblioteca back to /pages/biblioteca (and undoing what we did).

    To get the xml, yes. You just export it.

    Hope that helps.
  8. gldtn

    gldtn Well-Known Member

    Awesome, I've been reading a few articles and watching Kier videos to try to learn the system, but I need to freeshen up on my bear minimum php skills to try to build some basics mods for xenforo and maybe in the future some more advanced ones. Your help with this little addon made me understand the MVC model better, I read and even seen a diagram of the MVC, but was still unable to fully understand it until I digged into this :p (yeah I know, I can be a slow learner sometimes/being lazy and skipping through readme files contributes to this)

    Thanks once again for you help! Much appreciated!

    PS: It's actually Portuguese(from Brazil) ;)
    Arik likes this.
  9. gldtn

    gldtn Well-Known Member

    Here is the code I promised TerminalAddict;

    All I did is edited the code Arik wrote for me above with the extra pages you needed! Everything should work just fine, at least it did here on my end.
    1. Extract the zip file
    2. Upload PageNav/ to Library/
    3. Login to admincp and install new add-on with the addon_pagenav.xml file inside the zip
    Let me know if you encounter any problems! ;)

    Attached Files:

    glorify likes this.
  10. TerminalAddict

    TerminalAddict Active Member

  11. gldtn

    gldtn Well-Known Member

    I think it's because you have a link set in your admincp > Options > Basic board Information > Home Page URL


    Leave that blank and try it again.. Also, try changing in the plugin.php under the home, 'position' => 'middle' to 'position' => 'home' so it seats in the right place on you navigation bar.

    Is your home page url in the page editor Home or home?
  12. TerminalAddict

    TerminalAddict Active Member

    1. turn the home page url off in Basic Board Information
    2. Changed the position to home .. .awesome !!!
    3. home page url portion is: Home (capital H) .. but I could change it ?

    grep -R Home *
    ControllerPublic/Pages.php:                     $this->canonicalizeRequestUrl(XenForo_Link::buildPublicLink('Home'));
    Plugin/Plugin.php:                      'title' => 'Home',
    Plugin/Plugin.php:                      'href'  => XenForo_Link::buildPublicLink('Home'),
    Route/Prefix/Home.php:class PageNav_Nav_Route_Prefix_Home extends XenForo_Route_Prefix_Pages
    Route/Prefix/Home.php:          $request->setParam('node_name', 'Home');
    Route/Prefix/Home.php:          return $router->getRouteMatch('XenForo_ControllerPublic_Page', 'index', 'Home');
  13. gldtn

    gldtn Well-Known Member


    Download the PAgeNav.zip again, unpack and override the entire PageNav folder. Re run the xml file by selecting upgrade on the add-on drop down.

    Thant should do the trick and make your tab work correctly!
  14. TerminalAddict

    TerminalAddict Active Member

    wow .. that's awesome !!!!
    now I'm off to pick it to bits to figure out how you did it !!!
  15. gldtn

    gldtn Well-Known Member

    I was ripping my hair out for a minute, cause when I changed it to capitalized, it would just not work, so I started to get the idea Xenforo was caching it, or something, maybe Arik or someone else that has more knowledge on the field would be able to help us.

    But I changed everything to capitalized H and in the .xml file, it holds a line:
    <prefix original_prefix="Home" class="PageNav_Nav_Route_Prefix_Home" build_link="data_only"/>
    Which; original_prefix="Home" was lowercased. So by me updating that and upgrading it on xenforo, I believe it rebuild the cache with the correct prefix ? Lol I think I lost myself on trying to explain this ;P

    May someone out there share their knowledge, plz? ;)
  16. gldtn

    gldtn Well-Known Member

    Would someone help me or guide me to a tutorial how to set permission to these tabs? Basically I only want to show some tabs to certain usergroups. I don't want to add a toggle in xenforo permission system, I just want to hard code it into the plugin code:

    class Asp_Biblioteca_Plugin_Plugin
        public static function extendController($class, array &$extend)
            if($class == 'XenForo_ControllerPublic_Page')
                $extend[] = 'Asp_Biblioteca_ControllerPublic_Pages';
        public static function extendNavTabs(array &$extraTabs, $selectedTabId)
            $extraTabs['biblioteca'] = array(
                'title' => 'Biblioteca',
                'href'    => XenForo_Link::buildPublicLink('biblioteca'),
                'position'    =>    'middle',
                'linksTemplate'    =>    'biblioteca_subnav');
    Any help would be appreciated! Thanks!
  17. Brett Peters

    Brett Peters Well-Known Member

    Thanks guys, I found this extremely helpful
    gldtn likes this.
  18. SheepCow

    SheepCow Well-Known Member

    Grab the visitor and check the user groups before adding your extension to the extraTabs array, e.g.

    $visitor XenForo_Visitor::getInstance();

    if (...)
    // user is in the group, add the tab
    $extraTabs['mytab'] = array(...);
  19. glorify

    glorify Well-Known Member

    Thank you all for this. Much obliged :)

    Now, how would I add some subnavigation to that tab?
  20. gldtn

    gldtn Well-Known Member

    In /Plugin/Plugin.php you you define the template of the sub nav like so:

        public static function extendNavTabs(array &$extraTabs$selectedTabId)
    $extraTabs['biblioteca'] = array(
    'title' => 'Biblioteca',
    'href'    => XenForo_Link::buildPublicLink('biblioteca'),
    'position'    =>    'middle',
    'linksTemplate'    =>    'biblioteca_subnav')
    You would than create the template in the admincp

    Hope that helps!

Share This Page