Module Hooks
FUEL has extended the CodeIgniter Hooks system to provide extra hooks into creating, editing, and deleting of simple module data. An additional module hook parameter was added to allow you to add hook files in your advanced module folders (e.g. fuel/modules/my_module/hooks). To add a hook, you modify the fuel/application/config/hooks.php just like the native CodeIgniter Hooks.
The hooks currently available are:
- before_create_{module} - executed right BEFORE creating a new module item. The posted module item information is passed as an array to the hook class/function.
- after_create_{module} - executed right AFTER creating a new module item. The newly create module item information is passed as an array to the hook class/function.
- before_edit_{module} - executed right BEFORE saving the edited module information. The posted item information is passed as an array to the hook class/function.
- after_edit_{module} - executed right AFTER saving the edited module information. The edited module item information is passed as an array to the hook class/function.
- before_save_{module} - executed right BEFORE saving module information (for both create and edit). The new/edited posted module item information is passed as an array to the hook class/function.
- after_save_{module} - executed right AFTER saving module information (for both create and edit). The new/edited module item information is passed as an array to the hook class/function.
- before_delete_{module} - executed right BEFORE deleting of module item(s). The posted IDs of the items to delete are passed as an array to the hook class/function.
- after_delete_{module} - executed right AFTER deleting of module item(s). The IDs of the items deleted are passed as an array to the hook class/function.
The {module} part of the hook name is the name of the simple module that the hook applies to. Additionally, the {module} of "module" will be applied to all modules.
The following is an example of an advanced module named "projects" that has a hook file located at fuel/modules/projects/hooks/Project_hooks.php.
$hook['before_edit_projects'] = array( 'class' => 'Project_hooks', 'function' => 'before_edit_projects', 'filename' => 'Project_hooks.php', 'filepath' => 'hooks', 'params' => array(), 'module' => 'projects', );
How Are These Hooks Different Then Model Hooks?
Unlike model hooks, module hooks allow a module to execute code before or after an event in another module. This allows for more autonomous integration between modules. For example, say you want to integrate into the FUEL blog comment module to send an email notification to someone other then the author of the post (which the blog module does automatically). You can add an after_edit_blog_comments hook to the fuel/application/config/hooks.php file to make that happen.