HomePHP Page 3 - Building a Site Engine with PHP, Part 5
All your Modules Belong to MySQL - 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.
Modules get loaded into the database just like the plug-ins do. In the database you have two tables -- modules and module_status:
The modules table contains the same things that the plugins table does (only for the modules instead of the plug-ins) with one slight difference -- we’ve dropped the priority field and added a field for plugin_ID.
The module_status table is just like the plugin_status table; it contains the mod_ID which corresponds to the mod_ID in the modules table and the mod_status field. The mod_status field is also one of two values, “initialized” or “not_initialized”. Just like the plug-ins, these values tell the module loader to either load the module or not to load it.
When installing modules, start first with the modules table, put the module name in the mod_name field, and then put the directory that holds the modules in the mod_dir field. Once again this is the name of the directory that will hold the modules, beyond the plug-in directory. Then you need to fill in the mod_file with the name of the PHP file that makes up the module. Here’s a small example if you’ve forgotten the third article.
Let’s say you have a module in the following directory,
ROOT/plugins/foo_plugin/modules/bar.mod.php
Then the mod_dir would be “modules” and the mod_file would be “bar”. The reason we want it to be like this instead of the way we did it with the plug-ins is because it makes it easier for us to make multiple modules that use the same plug-in.
After you have the location set up, you’ll need to put in the plugin_ID of the plug-in that the module depends on. For example, if you have a plug-in named foo_plugin with a plugin_ID of 2, and the module bar.mod.php depends on foo_plugin to work. Then you’d put 2 in the plugin_ID field of the modules table for the bar.mod.php module. After that’s all done, you can fill in your optional fields which are mod_author, and mod_version, if you’d like.
Now in the module_status table, once again we need to put in the mod_ID which is an auto incrementing field in the modules table and is generated when we install a new module. Then we need to set the mod_status to either initialized or not_initialized depending on if you want it to load or not.