To start we must know what are the fields that we use to read/write in the database. That is, the fields that will store the information we want to read later.
I'll start setting the table name, fields and types of each:
simple_id -> The autoincrement field of each row.
simple_text -> This is the field that will contain our written text. Type: varchar; Lenght: 200;
simple_date -> This is the date when we write the text. Type: INT; Lenght: 10;
- The more precise you define the types of each field in your table, the better the performance.
Step 2 - Creating the installer
When creating an add-on for XenForo you should follow a standard structure, both in the creation of folders such as the naming of the classes.
All files in our add-on should be created in the folder forumroot/library/. This folder will also contain all other add-ons you have installed on your forum.
First of all, let's create a folder for our add-on. "But where?" You must be wondering. Inside the folder forumroot/library/. So start by creating a folder with the name of our add-on: "SimpleText".
This is the skeleton of the folder (note that I'm just listing the folder XenForo for reference):
----SimpleText -> our new folder!
Now that we've created the folder, we must create a file called Installer.php that will contain two methods: install() that creates the table and uninstall() it will delete this table (when you uninstall).
-----Installer.php -> Our new file!
We have our first folder and file in PHP. But what do we do with it? See the next step.
We all have dumb questions
A. The Installer.php will be our installation file for our add-on. You can put whatever you want. "Installme.php", "MyFileInstall.php" or previously "ThisFileDoNotHaveAName.php" (not recommended). But for better understanding, simply use "Installer.php", so we know what it is about this file. By creating an add-on, we have the option of selecting a class for installation (and method) and a class to uninstall (and method). So every time someone install/uninstall your add-on, this class / method is called. As this simple add-on uses a table in the database to record and read the data, we will use this property of the add-on to tell XenForo that: "XenForo when installing my add-on please find a class and call the method SimpleText_Installer::install(), ok?"