That would be great because there is no "Starting Guide" for beginners, and I mean beginners. All those developers have background in programming and they just need to adapt their skills to Xenforo/different language whereas real beginners don't understand the system. Sure all starters need at least basic programming knowledge like conditionals or functions and object-oriented programming, and stuff but that is not enough to see the "big picture". Specially when you are someone outside of this IT business. At least I feel like that and I would like to understand the "inside" stuff. I would appreciate that a lot.I've picked up a few things throughout my journey so far. I plan to write tutorials once I'm confident of my skills.
Thanks for the tutorial. How can I locate ControllerPublic? I can't find it on my cPanel, nor on XenForo admin panel and nor in the file manager. What am I missing?Part 1
This walk-through will take you step-by-step through the process of creating a working XenForo Add-on.
The Add-on created will allow Admins to prevent the editing of signatures for members with less than a specified amount of posts, and who belong to a particular group. To accomplish this we will need to set up a Listener, an Admin Options Page, and create the PHP files.
I decided to not use screen shots in this walk-through as I want to give the feel that you already know XenForo's Model View Controller (MVC) concept and are about to write your Add-on. Each step will be explained in detailed.
The working Add-on will be available at the end of this walk-through for coders to reference, or for licensed members to use.
If you plan on building the Add-on step by step you will need to enable Debug Mode. It is recommended that you first make a back-up of your config.php file before editing it. To enable debug mode:
open: yourForo -> library -> config.php
And add at the bottom: $config['debug'] = true;
At this time you may also want to add:
// $config['enableListeners'] = false;
Save your config.php file.
Creating the Add-on
Log into your AdminCP, and navigate to: Development -> Create Add-on
The following fields for this Add-on need to be filled with the following information:
Add-on ID: limitSigs
Title: Limit Signatures for new Members
Version String: 1.0
Version ID: 1
The Version ID is used internally to keep track of revisions. Increase this number for each revision.
The rest of the fields we do not need for this Add-on.
Click the Save Add-on button.
As the purpose of our Add-on is to not allow new members to edit (create) a signature, we must locate where members can edit their signature within XenForo, so we can Listen for the class being called. This is handled by a Controller. There are four Controller directories: Admin, Helper, Public, and Response. Editing a signature is not an Admin function. Nor is it a Helper, or a Response, that leaves us with Public. From your filemanager navigate to ControllerPublic. As editing a signature is part of a members account look for Account.php. Open this file and search for signature. The first word highlighted is just above: public function actionSignature(). This is the function we want to override.
Now we must listen for the class which this function belongs to be called (XenForo_ControllerPublic_Account).
XenForo comes with quite a few Listeners that we can choose from. Navigate to: Development -> Code Event Listeners. Click on the Create New Code Event Listener.
The first drop down allows you to select which event to listen to. As we want to listen to a class from the controller being loaded, from the drop down, select Load_Class_Controller.
The load_class_controller listener is tricky, but it is powerful and provides the most flexibility of all the Listeners. When you select this listener you will notice in the explanation of the load_class_controller that the class must be defined as: class My_Class_Name extends XFCP_My_Class_Name. This is true, but it can not be loaded directly. Loading this class directly will result in the AutoLoader to generate this exception: Cannot load class using XFCP. Load the class using the correct loader first.
What the error means is that the new class you want to create must be loaded before it can be resolved. But the question is, where does it get loaded, and how? This is the purpose of the $extend array argument.
Thanks for the tutorial. How can I locate ControllerPublic? I can't find it on my cPanel, nor on XenForo admin panel and nor in the file manager. What am I missing?
Also, I second the things about having a development tutorial for beginners. It would be awesome. I am a complete newbie myself, but would love to know more about how XenForo forums are programmed (and how to develop add-ons myself to be cost effective haha).
Hi, the best thing to do to get started is to download some simple add-ons and go through them. I recently uploaded a few add-ons that are small in size, and fairly straight-forward to navigate through, that would be a good pace to start,No one?
If you're not familiar with PHP, there are various sources of information:Lawrence, thanks for your suggestion. I don't even know what a 'class" is. Don't I need to know these these things before I can parse an already written addon?
Is there a source for me that language that I can look up these things?