Creating extensions in EE is a great way to extend the system to do whatever the heck you want! However, in my experience, I find my self creating “ad hoc” extensions–extensions that are only applicable in my application in my circumstances. They are not meant to be packaged up and redistributed. Working with extensions like this can be a pain. First you have to make an extension class, then you have to activate it. If you want to add another method, you either have to add that to the database manually, or “upgrade” your extension. Same thing goes with extension development. Or maybe you just want to try out a hook? Why go through all that pain?
Maybe you have your development split amongst different computers, each reading from the same database. If you want to try out an extension, you would have to have the physical extension files on each computer, otherwise you would get an error on the other ones. Of course you can copy the files to those other computers, but sometimes its inconvenient. Especially if you’re not sure your going to use that extension.
Dynamic Extensions solves this niche problem. It reads a config file which combines the extensions loaded through the database with the ones in the config file. No more activating extensions. No more database hacking.
Usage is really simple: After putting in the one extension file in to your extension directory, create a file “extensions.conf” in the root of your “system” directory.
Lets assume you are writing “ad hoc” extensions, and you’re putting the methods in a class My_extensions.
You have a method which uses the hook sessions_end to some custom processing in your application.
In extension.conf, put the following in:
<?php
return array(
"sessions_end" => array ( //The hook
"10" => array( //The priority
"My_extensions" => array(
"0" => "sessions_end", //The method
"1" => "" //Any settings in an array format.
)
)
),
"unregistered_extensions" => array("My_extensions") // If your class has no mention at all in the DB (which is really the point of this), you'll have to add it here. Otherwise it won't get a "version" and you'll get a lousy E_NOTICE about an undefined index
);
That’s all there is to it!
Let me know if you guys find this useful, or if there are any issues with it.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.