Overload Classes
|
ATK Howto: Overload Classes
|
Intro
An overloader is a way of replacing one of the classes your app normally uses, with one of your own. A plain text example: "Use mymodule.mycustomprojectnode whereever the app normally uses the projects.project node". In other words, it is a way of modifying the app, without touching its code.
Example
To create an overloader, put this in your module.inc, near the top of the file (before the module definition):
$overloaders["project.project"] = "mymodule.mynode";
In your mymodule module, create the node mynode, like this:
include_once(moduleDir("project")."class.project.inc");
class mynode extends project
{
function action_admin()
{
echo "Hello World";
}
}
In this example, the project node is replaced by a mynode node, which derives from project, but overrides its action_admin behaviour.
Conclusion
It's not strictly necessary to derive from the original class, but this ensures that the overloader is compatible with the original. (The code in the application relies on the project node having certain attributes and behaviour, and by deriving from that class, we preserve this as much as possible.)
original from: http://forum.achievo.org/forum/viewtopic.php?t=1764