• 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

Arik

Well-known member
I don't need it to appear in the forum list, how can I build a route prefix pointing to the url as you mentioned? Or do you know of any thread here that can shed a light?

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.
 

Attachments

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.

(and with this, I'm thinking that this thread might need to be split, as it doesn't really have much to do with the original topic)

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?
 
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?

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.
 
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?
 
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":
Code:
<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!
 
Got it.. I thing when I was changing the code from bibleoteca to biblioteca, I must of did something wrong!

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

Also in your zip file in the xml you left active="0":
Code:
<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 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.

I understand the plugin part, but the I'm not totaly 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!

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.
 
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.

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) ;)
 
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! ;)
 

Attachments

wow .. thanks ! works perfect with the server page: http://www.fps.net.nz/community/servers/ doesn't work with the home page: http://www.fps.net.nz/community/pages/Home/ I did a find and replace on all your code, replace lowercase home with Capitalised Home Doesn't seem to have made a difference

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

leave_this_blank.webp

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?
 
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?
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 ?

Code:
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');
 
Terminal,

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!
 
wow .. that's awesome !!!!
now I'm off to pick it to bits to figure out how you did it !!!

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:
Code:
<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? ;)
 
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:

Code:
<?php

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!
 
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:

Code:
<?php

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!

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

PHP:
$visitor = XenForo_Visitor::getInstance();

if (...)
{
  // user is in the group, add the tab
  $extraTabs['mytab'] = array(...);
}
 
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.
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! ;)

Thank you all for this. Much obliged :)

Now, how would I add some subnavigation to that tab?
 
Thank you all for this. Much obliged :)

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

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

PHP:
    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!
 
Top Bottom