Hooks



Hooks work by intercepting users' actions (inserts, deletes, edits, selection of records, ... etc), and controlling what happens on each action.
AppGini Hooks is a means of advanced customization of AppGini-generated code. Prior to AppGini 4.50, code customization was a painful process, since all customizations you had manually made needed to be re-applied if you regenerated the code later. Even if using a CVS system to manage code changes, it was still a time-consuming task to compare code versions and re-apply customizations.

Using hooks, your code customizations are separate from the generated code. This way, they don't get overwritten on code regeneration and your project is ready for use directly after code generation without any further modifications.

How does it work?

To use hooks, you should place your code modifications in the "hooks" folder. This folder contains a set of files that AppGini creates only once and they don't get overwritten later. These files contain hook functions that you can define. AppGini code calls these functions when performing specific tasks and executes the code you define in them.

For example, to send a notification email when a new order is added to the orders table, you should add the mail sending code in the orders_after_insert() function inside the hooks/orders.php file. This function is automatically called by the AppGini-generated application whenever a new record is created in the orders table. Any code you place inside that function is executed when a new record is added to that table.

Hooks were added to AppGini as of version 4.50. Older versions don't support this feature.