HomePHP Page 2 - Building a Site Engine with PHP, Part 5
Plug it in, Plug it in! - PHP
So you want to use your site engine that you’ve been working on? Okay, now is the time for me to show you how to add plug-ins, modules, blocks, and templates to your database so that they will work with your engine. It’s not that hard to do, and with just a few simple steps, you’ll be running your site off your new stylish site engine in no time.
Once you’ve got a GUI for MySQL (unless you plan on going all out commando with it and using the command line), you can start with your plug-ins. Since everything depends on the plug-ins, I’d say you have to start with the plug-ins, but it is your choice.
In the database there are two tables for the plug-ins -- the plugins table and the plugin_status table:
The plugins table contains all the information about where the plug-ins are located, their ID’s, what they are named and their loading priority. It also has a few optional fields that contain the author’s name and the plug-in’s version.
The plugin_status table only contains two fields, neither of which is optional. The first one is the plugin_ID which corresponds to the plugin_ID in the plugins table, and the plugin_status field. The plug-in_status field is one of two values, “initialized” or “not_initialized”. These values tell the plug-in loader to either load the plug-in or not to load it.
The first thing you need to do when installing a plug-in is name it in the plugin_name field in the database; it can be anything you want it to be. The name of the plug-ins has nothing to do with the functionality of the site engine at all; it’s only for your personal reference. Then put in the name of the directory that the folder for the plug-in can be found in. If you followed the suggested directory structure outlined in article three, you’d put “plugins” in this field named plugin_dir. Then you need to put the name of the plug-in’s folder in the plugin_file field; for simplicity sake we just use the name of the folder that contains the plug-in as the plug-in file. If you remember back to the second article, we did this because it’s better for organizing and loading the plug-ins and we just names the PHP file for the plug-in main.plug.php. After that you have the plugin_priority field, this tells the engine if there’s any plug-ins that need to be loaded before others. The higher the number, the sooner it’s loaded.
For example if you have plugin1 with a priority of 0, plugin2 with a priority of 2, and plugin3 with a priority of 1, they will be loaded in the following order.
As for the plugin_author, you can put in your name, or the name of the person that made the plug-in, or you can be like me and completely leave it blank. You can do the same thing for the plugin_version field.
In the plugin_status table, you have to add a row that contains the plugin_ID that is the same as the plugin_ID in the plugins table, which is auto incremented when you add your new plug-in. Then you have to tell it to either set the plug-in as initialized or not_initialized in the plugin_status field. Keep in mind if you set it to “not_initialized” the engine will not load it.