Fuhrmann
Well-known member
Step 1 - Setting the table
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:
Table:
xf_simple_text
Fields:
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):
forumroot
--library
----SimpleText -> our new folder!
----XenForo
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).
forumroot
--library
---SimpleText
-----Installer.php -> Our new file!
---XenForo
We have our first folder and file in PHP. But what do we do with it? See the next step.
Q. Why use the name Installer? And why create this file? What's the use?
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?"
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:
Table:
xf_simple_text
Fields:
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;
- Whenever you need to create a table in the database, follow a pattern. Put the name of your add-on along with the prefix of the other tables in your XenForo.
- 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):
forumroot
--library
----SimpleText -> our new folder!
----XenForo
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).
forumroot
--library
---SimpleText
-----Installer.php -> Our new file!
---XenForo
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
Q. Why use the name Installer? And why create this file? What's the use?
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?"