1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

When creating an add-on...?

Discussion in 'XenForo Development Discussions' started by Nasr, Mar 12, 2011.

  1. Nasr

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

    Brogan XenForo Moderator Staff Member

    Nasr likes this.
  3. Nasr

    Nasr Well-Known Member

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

    Shadab Well-Known Member

    A simplified explanation...


    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.


    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.
    DaveL, dmnkhhn and Nasr like this.
  5. Nasr

    Nasr Well-Known Member

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

Share This Page