When creating an add-on...?

Nasr

Well-known member
When creating an add-on, can one of you please explain where to put certain things. For instance, listener.php as showen by Kier will always deal with template hooks?

What about database info, does it go in the datawriter? can anyone list the ways a programmer should go about doing a xenforo add-on? Thanks.
 
Have you seen this thread: http://xenforo.com/community/threads/creating-an-addon.5416/

And also the other threads in that forum?

They should give you a start at least.
I did see that. And it's very helpful. However, I'm still not sure what goes where. For instance, what goes in Model? what goes in datawriter? what goes in listener etc.. Does xenforo have a certain way of dividing these things? I'm interested in learning how to create add-on's. Doing this as a hobby.
 
A simplified explanation...

Model:

Your model class mainly handles fetching of data; usually from the database. So this is where all your hand crafted SELECT queries would be placed. Performing an sql query from anywhere else (for example, from a controller class or heaven forbid, a view class) is a bad idea.

DataWriter:

As the name suggests, a DW is responsible for manipulating data. ie, it would handle insertion, updation and deletion of data from the database. One thing you'd notice is a datawriter handles one row at a time. So unlike your Model from which you can select a bunch of rows in one go; a datawriter can manipulate a single row of data, only.

Using a datawriter to manipulate data has an added benefit of maintaining integrity of your data.

Event Listeners:

Whenever you set up a code event listener via the Admin Panel, you have to specify a "callback" method which would be executed when your selected event occurs. This callback method can be placed in ANY class of your choice. Most devs choose to place these methods in a "Listener.php" file, to make it obvious to the reader. But it's not a requirement. I place such methods in an "Addon.php" file, along with the installer code, as I find it easier to manage that way.
 
A simplified explanation...

Model:

Your model class mainly handles fetching of data; usually from the database. So this is where all your hand crafted SELECT queries would be placed. Performing an sql query from anywhere else (for example, from a controller class or heaven forbid, a view class) is a bad idea.

DataWriter:

As the name suggests, a DW is responsible for manipulating data. ie, it would handle insertion, updation and deletion of data from the database. One thing you'd notice is a datawriter handles one row at a time. So unlike your Model from which you can select a bunch of rows in one go; a datawriter can manipulate a single row of data, only.

Using a datawriter to manipulate data has an added benefit of maintaining integrity of your data.

Event Listeners:

Whenever you set up a code event listener via the Admin Panel, you have to specify a "callback" method which would be executed when your selected event occurs. This callback method can be placed in ANY class of your choice. Most devs choose to place these methods in a "Listener.php" file, to make it obvious to the reader. But it's not a requirement. I place such methods in an "Addon.php" file, along with the installer code, as I find it easier to manage that way.

Exactly what I was looking for. Thank you very much.
 
Top Bottom