Advice on learning to develop XF plugins for a non-programmer?

Ludachris

Well-known member
I've already asked a couple developers here privately, but figured I'd ask in this forum. If you were to start from the beginning with very little experience in programming anything from scratch, and considered yourself to not really be the programming type, what would be the most efficient route you would take to learn the XF architecture and how to develop XF plugins?

I've had some decent experience picking up books and learning that way, but I usually learn best with visuals and examples. I've been able to tweak some PHP code to make things work the way I need, did that a lot in vB over the years, and I've also done a little Ruby coding, but very simple stuff - if nothing else it just introduced me to the MVC philosophy. But I know I need a better foundation.

I have been looking at these two books to help give me a better foundation, and to have as a desk reference:
http://www.amazon.com/gp/product/0321733452/
http://www.amazon.com/gp/product/0321832183/

I tried looking through PHP.net and can't find a good way to use that site as an effective learning tool. Once I have a better foundation maybe it will be more useful for me. I started a few CodeAcademy exercises but I don't know if that's the most efficient way to go. I wish there was a way that I could just learn while working with XF code.

Any advice would be appreciated. It's been over 15 years since I taught myself HTML and started deciphering wwwboard CGI and email form scripts to customize them for my needs. I wish I had put more effort into learning how to code back then when it seemed easier to get things to "click".
 
Hey Ludachris,

It depends on the way your learning style is.Code Academy is good for beginning to learn the basics of php Php.net is great for remembering some things. I'm new to developing XenForo to. I look at add-on code to try understand code to work with . Stay motivated don't be afraid to ask questions on here if you get stuck on something.
 
Hey Ludachris,

It depends on the way your learning style is.Code Academy is good for beginning to learn the basics of php Php.net is great for remembering some things. I'm new to developing XenForo to. I look at add-on code to try understand code to work with . Stay motivated don't be afraid to ask questions on here if you get stuck on something.
Thanks Kirk, I keep coming back to the idea that for what I'm wanting to do and the projects I want to work on for a living, I really need to learn to program. You either have to pay people and depend on people having availability or do it yourself. And I don't always have the money and can't always wait on people to find time. It just makes sense for me to learn to code if I'm going to build the type of sites I want to build.
 
Just start with basic php as "$var = 5; echo $var;". After that you learn basics like loops etc. This is the *most* basic.

For xenforo you would have to learn how it all works together, the controller is what you should look at first. Some addons here are coded just within the controllers. Actually you should put the database related code within the model, but you can even put it also within the controller (which is bad practise). So when you learned the php basics, look at the controller here, the code is located at domain.com/library/ControllerPublic/* Here you will find some interesting code that you even might understand when you are at a beginners level.
 
Thanks Marcus, good to know. I think I'm good with the basics, but beyond that it's all iffy for me. Knowing that the model is where the SQL queries is supposed to go is a great tip. That's the type of thing I need to learn - how to structure code, why to do certain things, etc. What is considered standard practice in terms of PHP and what is standard practice in XF.
 
Just forget the "View" for the first months of coding, and only concentrate on the ControllerPublic. Here is all the code you already know. You may wonder how the variables from the code are given to the xenforo templates: At the end of each function one array $viewParams is passed and you can use all data from this array in your xenforo template. At the same line with $viewParams, there is also the template named, and in this template you can use the variables from $viewParams.

It's pretty easy and straightforward, but you have to know where to begin.
 
Just forget the "View" for the first months of coding, and only concentrate on the ControllerPublic. Here is all the code you already know. You may wonder how the variables from the code are given to the xenforo templates: At the end of each function one array $viewParams is passed and you can use all data from this array in your xenforo template. At the same line with $viewParams, there is also the template named, and in this template you can use the variables from $viewParams.

It's pretty easy and straightforward, but you have to know where to begin.
More great info that I didn't realize before, thanks a ton Marcus!
 
You definitely need to read up on object oriented development to be able to grasp what the guys are getting at.
 
The best way to understand how XenForo works, is to look at XenForo code. Everything can be found in obvious files thanks to Kier and Mike's naming and coding conventions.

For example every url you go to is immediately resolved into a Controller; If you're in the admin panel it leads to ControllerAdmin, if you're in the public realm it leads to ControllerPublic. Right now we're looking at /community/threads, you can gather that this leads to /library/XenForo/ControllerPublic/Thread.php.

Since there's no action specified, you need to look at the actionIndex() function. If you go up and hover the "watch thread" button you'll see an example of an action being included. That function is in the same controller, actionWatchConfirm().

In the controller/action you'll see that all the data preperation is handled. Checks are run to make sure you can view this thread and it gets the thread (and other data) from models. You can access a model from the controller via two methods: $this->getModelFromCache('Model_Name') or XenForo_Model::create('Model_Name'). You can see which model is being called by looking at the first argument. The model can be found in a corresponding file. All classes can be changed to their file location by replacing "_" with "/" and prepending /library/ so for example XenForo_Model_Thread results in /library/XenForo/Model/Thread.php.

Your controllers always need to return a response. $this->responseView('ViewRenderer', 'template', $viewParams) is the most common. You can ignore the ViewRenderer part, or this is where you can do some last minute changes to variables, for example run parameters through a bbcode parser. That class path doesn't have to exist. The second argument is the template name that will be loaded. The third parameter is an array with your data that can be accessed in the template.

DataWriters are the next biggest thing. The datawriter should have the structure of your database table and should specicify the type of data that should be sent. I would recommend looking at existing ones (I don't want to use Discussion and Messages as examples of this because of how they extend each other, they're much more advanced). Take a look at /library/XenForo/DataWriter/CodeEvent.php, this is a pretty straight forward one.

Leaving this for a reference for coding php in general: http://www.phptherightway.com/
 
Last edited:
Top Bottom