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


Discussion in 'XenForo Pre-Sales Questions' started by Liam W, Apr 12, 2013.

  1. Liam W

    Liam W Well-Known Member

    I didn't think I liked XenForo - I refused to use anything other than vBulletin until an hour or so ago ;-)

    I have now decided, after looking over this forum for a while, that I like XenForo.

    Just a quick question though, how are mods made? In VB 4, they are just php code run at hooks at places in the code. This was really easy. vB5 looks more like the WHMCS system, which I find complex and confusing.

    So what is the XenForo system?

    Also, I was in doubt as to where to post this so I posted it in off topic (if in doubt, it's off topic ;)).

    Miner, 0xym0r0n, Crayo and 1 other person like this.
  2. Shelley

    Shelley Well-Known Member

    Best place is probably pre-sales if your still considering xenforo and you haven't purchased yet.

    Edit: one of the advance coders is probably better suited to answer your query so I'll leave that one for them. :)
  3. Liam W

    Liam W Well-Known Member

    (Was looking for the quote button then)

    Well, I was going to say that first impressions weren't good, however the subscription email didn't contain your edit obviously, which made it much better ;-)

    (Before the edit, you came across as unfriendly. It's a amazing what a smiley can do ;))
    Shelley likes this.
  4. Kevin

    Kevin Well-Known Member

    Liam W likes this.
  5. James

    James Well-Known Member

    Read through the Have You Seen...? section of the Official Forums to answer this question in detail.

    Modifications here are made by extending XenForo code, to put it in simple terms.

    Here are some links:
    http://xenforo.com/community/threads/how-to-use-template-hooks.13167/ (deprecated as of here)
    Liam W likes this.
  6. Shelley

    Shelley Well-Known Member

    I actually thought that myself after I read it back and made the edit. But of course that wasn't the intention but I can see how you would think that as I thought it myself after reading it back. :)
  7. Liam W

    Liam W Well-Known Member

    Nice guide that, although it does look like XenForo mods are complicated :-(

    Nice link bunch there, but you're up a bit late aren't you ;-)
  8. James

    James Well-Known Member

    It's only 12:35am! Early...
    Shelley likes this.
  9. Liam W

    Liam W Well-Known Member

    Early bird catches the worm or whatever...

    (You could also have noted the fact that I'm in the same time zone as you... :p)

    Few, thought it was just me, like usual :) I'm really starting to like this community!

    Edit: Aw, Shelly I can't see your profile :-(

    Also, when was this thread moved and by who...
    Shelley likes this.
  10. Teapot

    Teapot Well-Known Member

    It's worth noting that XenForo's code is MVC, so it's slightly more complicated at a glance. But once you learn how MVC works - and there are excellent tutorials here to teach you the basics of creating a good add-on - the code is very very clean, well documented (either in the code itself, or you can point PHPDoc at it), and very easy to work with.

    As an example: My PHP experience before starting to work on XenForo add-ons was virtually nil. I'd picked up the absolute basics of crappy procedural code, knocked lumps out of a few free (also crappy) forum packages for fun, and then never did anything with that knowledge for several years.

    Now, I am currently about half-way through creating an entirely custom feature (an integrated writing and art gallery), have made quite a few small mods for various things, and have lofty plans for a lot more. This is from following some tutorials here, then learning from the XenForo code itself as to the best way to do things. So although it's not immediately obvious as to how to do things, it's very easy to pick up and work with.
    Liam W likes this.
  11. Liam W

    Liam W Well-Known Member

    Hmm, googling MVC now.

    Googled, reading a site about it.

    Doesn't look too bad, but I haven't been past page one yet...
  12. James

    James Well-Known Member

    Instead of learning about MVC in a general sense, I'd recommend just looking at existing free add-ons here and trying to understand the basics of how they work.

    MVC sounds complex, but it makes sense when you look at the code if you have some basic PHP knowledge.
  13. Liam W

    Liam W Well-Known Member

    Will do that, thanks.

    Just need an XF license however, maybe I should sell my vB...
  14. Teapot

    Teapot Well-Known Member

    The short answer is: MVC stands for Model, View, Controller.

    The idea is to separate your code so each function is only doing one job and doing it well. This means that other code can hook into it without any troubles.

    Models are the modules that deal with reading data. For instance:
        public function countWorksByUser($userId)
                SELECT COUNT(*) AS total
                FROM cc_work AS `work`
                WHERE `work`.user_id = '
    This bit of code counts the number of entries a user has in my custom tables. This is useful because several different things might want to count the works a user has - the cron job for awarding trophies, a permission system (for if I want to limit the number of works a user can create), and so on and so forth. I can just point them all at this code and have a single point of failure.

    Controllers are the engines of your code - they actually do things. For instance, controllers are in charge of receiving the data from the models and working them into a form that can be used by a View. One of my simplest controllers is:
        public function actionNew()
    This is called by XenForo's routing system (which is a topic outside the scope of this post), and simply calls my function for checking user permissions, and then responding with a View.

    Views are in charge of turning the data the controller has worked with and presenting it - whether that be to the user, or as a JSON request, or otherwise. The nice thing about XenForo views is that a lot of the time they don't need to actually exist - CreativeCorner_ViewPublic_New does not resolve to a real View, as XenForo takes care of that for me. Although you don't need to actually do this yourself, most Views take the data and tell XenForo to output a template.

    There are also DataWriters, which basically tell XenForo about the database and your tables - and of course are used in extending XenForo's methods that write to the database.

    This isn't designed to be an tutorial or anything, just an illustration of the basic elements. I strongly recommend you follow through some of the Development Tutorials, which do a far better job of explaining things than I do :D
    Kim, Pereira and Liam W like this.
  15. Liam W

    Liam W Well-Known Member

    Very nice post, that actually made me understand - thanks!
    Kim and Teapot like this.
  16. Shamil

    Shamil Well-Known Member

    Just a very small note that the model layer, not model class -for people new to the concept- manipulates the data, as well as receiving it.

    Otherwise, good intro to MVC as commonly applied in PHP.

Share This Page