A very simple question...

Marcel

Active member
..but something my brain won't let me answer. I'm sure the answer is staring me in the face.
I'm writing a plugin which presents a navigation dropdown menu. The options on that menu will all be searches but with different parameters.

How do I pass the value of which menu item was selected into the my controller > function to decide what to do.
I'm not talking if or switch statements, I mean actually passing that value to the function.

For the menu I've created a class/listener that listens for navigation_tabs, and adds the menu on via a template. At the moment, the links for each <li> are null, but that ties into my question.

I have a feeling the answer is embarrassingly simple.

BTW the output of each menu choice will be the same, it will be a list of threads as a search result.
 
The selected navigation tab is set via Route Prefixes in the code. Are you expecting the tab to be selected when visiting a page?
 
Hi Jeremy,

I think my question is simpler than I'm making out. Well it's either much simpler, or it's much more complicated than I thought.

Basically, the plugin will be a menu of about 5 items, each with a specific search.
EG

Item1 - All threads from x forums with unread posts
Item2 - All threads from y forums with unread posts
Item3 - All threads from y forums with yy prefix, with unread posts
Item4 - All threads from x and y forums with zero replies

So each link will perform a search and return a list of threads. Therefore I will still be stying on the 'forum' tab, and maybe have the links / menu on the subnav.

At the moment, what I've learned to do with XenForo is to extend on what functionality is there via a listener, rather than branch into my own functionality....(which will be an extension of the xenforo search, if that makes sense).
To do this within vBulletin, I would have just created a hard link in the navbar template, linking to a PHP which does all the work and includes templates and css as required.

To do this with XenForo...
I'm thinking these links need to call a function(or functions) from with a controller, which then passes the search data to a function within a model which does the actual search, returning the results to a view to be parsed through a template.
That's now where I'm stuck.
Route prefix? ViewPublic? ControllerPublic? DataWriter?

I suppose my question is broader than I thought, but also covers stuff that I should really know. Not sure where to start now....
I've had a look through other plugins that I think will have similar structures, but they tend to be part of bigger collections, and as such have centralised code that will work with other plugins in the collection, so it's too advanced for me to pick apart and understand it.
 
You can rule out DataWriter already ;)

You do this from the Model. See XenForo_Model_Search for details.



An oversimplified version of the MVC arch explanation in XenForo is:

Model - Application Logic
Controller - PHP part of the UI (which in most cases does NOT contain logic - just method calls to to the model and maybe do some work on it, but its primary goal is to display the results in a meaningful way)
View - Output part of the UI, regardless of presentation method (HTML, XML, JSON... in xF you can override the PHP methods that generates the output as necessary)

Additional parts of XenForo used pretty much everywhere:
DataWriter - Handles database interactions (a Model in some web frameworks, however this behaviour is not really MVC)
Helpers - A bunch of static functions
Cron - Execute tasks regularly
Deferred - Execute long-running tasks in background by breaking them up into chunks (Fun fact: This is not first used by jQuery but first used by Twisted, the event-driven network framework in Python, also my favourite library)
 
Thank you very much, I'll take a look at the search model.
This is the sort of explanation I've been looking for.
While I think I have an understanding of MVC architecture in general, I also understand that it's a very fluid and adaptable concept, so where I could put one bit of code, I could easily put it in other areas that aren't consistent with best practice.
Therefore it's how the MVC model applies to XenForo and indeed the structure of XenForo itself that's next on my learning list.
 
Top Bottom