and better understand, the following
Note the very little difference between
_before
- and
_after
-hook:
Code: Select all
function persons_before_insert(&$data, $memberInfo, &$args)
{
// $data passed by reference
// changes in $data[...] will be stored
return TRUE;
}
function persons_after_insert($data, $memberInfo, &$args)
{
// $data passed by value
return TRUE;
}
Before
In
_before
-hook,
$data
-variable is passed by reference. Note the
&
character:
&$data
.
Here you can change the values of
$data
-array. AppGini will get back
$data
-variable and save the
$data
array's values to db afterwards, then call the
_after
-hook.
After
This time, AppGini fetches fresh data from database, then AppGini is passing
$data
-array by value, not by reference (without
&
).
You can do whatever you want with
$data
variable in
_after
-hook, for example do your own changes in database by using SQL commands, but after leaving your
_after
-hook, AppGini will
not save changes you made to
$data
.
Actually, AppGini does not even know anything about your $data
-changes outside _after
-hook, because $data
is passed by value, not passed by reference, which means $data
is a (local) copy which can be seen inside your function, only.
On Insert
DV-Form ―POST➞
_before_insert(&$data)
âžž insert
$data
into DB by AppGini âžž
_after_insert($data)
âžž set record owner
On Update
DV-Form ―POST➞
_before_update(&$data)
âžž update
$data
in DB by AppGini âžž
_after_update($data)
So, if you want to make changes to $data and want AppGini to store them, always do this in before-hook. Use after-hook for additional tasks, for example for custom calculations based on previously stored values.
PS: Caution with before_delete and after_delete: after_delete the record will not be in database any more.