- Joined
- Jan 1, 2001
- Messages
- 60,189
Sometimes I get the question: How do I know when to use what, or what does this stand for?
I do not know the answer, well, a little. I am still learning, but I will share what I know so far.
XenForo uses a framework, some stuff is from Zend, the majority is their own. But compared to many frameworks for PHP it's kinda the same, kinda.
You will find add-ons with directories such as Route/ Listener/ Controller/ Model/ etc.
Here's my quick and dirty explanation that helps you get started. And by all means, please do extend on it in the comments, I need to improve what I know (big time).
Route
Usually not used, unless you have to introduce a new route or manipulate one.
For example, the XenFans "Popular Content" plugin uses a route, because it is a new .com/popular/ page.
Listener
Used when you have code event listeners, such as injecting your own template inside existing templates. Great for certain customizations where you want upgrades to new versions to be smooth, without touching the original templates. The XenFans "Extra Tabs" plugin uses this to add additional tabs to the navigation template.
Model
Used to communicate with the database, you get data in there, use it to query the database, and get data out of there. The XenFans "Promoted Accounts" add-on for example uses this to get the right users from the database. So we know which accounts are promoted (that we want to display later).
Views
Or ViewPublic or Public, this seems to vary a bit with XenForo, but it's a helper for the templates. Basically once we're done with whatever we have, we parse it back on to the templates and get an output to the user. Maybe it's that English isn't my first language, but I find it a bit hard to explain this one properly.
Controller
This is basically the guy that takes the input, decides how to handle it and directs the rest of the system as to what to do next.
Now that we have a beginners idea of what things are, in a very dirty and simple visual explanation you could view it like this.
When someone goes to say /popular/ it has to be a route that exists. So we need a Route.
Since we now want something, let's provide the Controller with some data. Which could call a Model if some data has to be queried. And pass it on to a public viewer that handles the template and gives it what it needs.
So some plugins don't need a new Route, some don't need a model.
Sometimes it's as simple as 'hook into this template, with our template' and creating a code event listener for this is enough.
And basically if you need to think about creating a plugin you need to go through the thinking steps of 'is it a separate new page? does it need to query data from the database? do i need to create my custom templates? etc.' Which might help you get started prototyping your add-on. Slowly populating the files until you end up with a working alpha ready for testing.
I am looking forward to you guys posting better explanations, perhaps I am simply seeing this incorrectly, please let me know.
I do not know the answer, well, a little. I am still learning, but I will share what I know so far.
XenForo uses a framework, some stuff is from Zend, the majority is their own. But compared to many frameworks for PHP it's kinda the same, kinda.
You will find add-ons with directories such as Route/ Listener/ Controller/ Model/ etc.
Here's my quick and dirty explanation that helps you get started. And by all means, please do extend on it in the comments, I need to improve what I know (big time).
Route
Usually not used, unless you have to introduce a new route or manipulate one.
For example, the XenFans "Popular Content" plugin uses a route, because it is a new .com/popular/ page.
Listener
Used when you have code event listeners, such as injecting your own template inside existing templates. Great for certain customizations where you want upgrades to new versions to be smooth, without touching the original templates. The XenFans "Extra Tabs" plugin uses this to add additional tabs to the navigation template.
Model
Used to communicate with the database, you get data in there, use it to query the database, and get data out of there. The XenFans "Promoted Accounts" add-on for example uses this to get the right users from the database. So we know which accounts are promoted (that we want to display later).
Views
Or ViewPublic or Public, this seems to vary a bit with XenForo, but it's a helper for the templates. Basically once we're done with whatever we have, we parse it back on to the templates and get an output to the user. Maybe it's that English isn't my first language, but I find it a bit hard to explain this one properly.
Controller
This is basically the guy that takes the input, decides how to handle it and directs the rest of the system as to what to do next.
Now that we have a beginners idea of what things are, in a very dirty and simple visual explanation you could view it like this.
When someone goes to say /popular/ it has to be a route that exists. So we need a Route.
Since we now want something, let's provide the Controller with some data. Which could call a Model if some data has to be queried. And pass it on to a public viewer that handles the template and gives it what it needs.
So some plugins don't need a new Route, some don't need a model.
Sometimes it's as simple as 'hook into this template, with our template' and creating a code event listener for this is enough.
And basically if you need to think about creating a plugin you need to go through the thinking steps of 'is it a separate new page? does it need to query data from the database? do i need to create my custom templates? etc.' Which might help you get started prototyping your add-on. Slowly populating the files until you end up with a working alpha ready for testing.
I am looking forward to you guys posting better explanations, perhaps I am simply seeing this incorrectly, please let me know.