Add functions (pre/post/...) to an existing node: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
{{howto|Advanced|[[Thomas Holz]] <vhskids@gmx.de>}} | {{howto|Advanced|[[Thomas Holz]] <vhskids@gmx.de>}} | ||
Modifiers allow you to modify nodes on before they are used. To add [[ | Modifiers allow you to modify nodes on before they are used. To add [[triggers|functions like preUpdate]] use [[atkTriggerListener]] | ||
| Line 17: | Line 17: | ||
class mod_mymodule extends atkModule | class mod_mymodule extends atkModule | ||
{ | { | ||
function module_node_modifier( | public function module_node_modifier($node) | ||
{ | { | ||
atkimport("module.mymodule.myListener"); | atkimport("module.mymodule.myListener"); | ||
$node->addListener(new | $node->addListener(new myListener()); | ||
} | } | ||
} | } | ||
| Line 32: | Line 32: | ||
class MyListener extends atkTriggerListener | class MyListener extends atkTriggerListener | ||
{ | { | ||
public function preUpdate( &$record ) | |||
{ | |||
do some code.... | |||
return true; | |||
} | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 13:52, 12 February 2010
|
ATK Howto: Add functions (pre/post/...) to an existing node
|
Modifiers allow you to modify nodes on before they are used. To add functions like preUpdate use atkTriggerListener
Example of using atkTriggerListener:
Add the following code in your module_preload.inc (if this file is not present, create it in your module's directory):
$modifiers[] = 'modules.node';
In your module.inc:
class mod_mymodule extends atkModule
{
public function module_node_modifier($node)
{
atkimport("module.mymodule.myListener");
$node->addListener(new myListener());
}
}
now setup class.myListener.inc. The Listner contain the new functions. They will be called automatically by the node.
atkimport("atk.utils.atktriggerlistener");
class MyListener extends atkTriggerListener
{
public function preUpdate( &$record )
{
do some code....
return true;
}
}