Page 1 of 1

Hook for children-parent

Posted: 2017-10-28 23:46
by landinialejandro
Hi!
I was looking for a way to modify the children table without having to rewrite the code each time the application is compiled.
and I came up with the idea of ​​implementing a Hook in the "parent-children.php" file.
I put the following code: (just before / * process requested operation * /)

Code: Select all

if ($ChildTable) {
            $function_name = $ChildTable. '_init_child';
            @include ("$currDir/hooks/$ChildTable.php");
            if (function_exists ($function_name)) {{
                            $args = array ();
                            $render = $ function_name ($userPCConfig [$ChildTable], getMemberInfo (), $args);
                    }
        }
and now I put the function "tablename_ini_child" inside "tablename.php" inside the hook folder and I can modify some parameters before visualizing the children table.
This would allow to keep a lot of code without needing to rewrite it (or re-paste it).

In my case, for example, I change the number of 'records-per-page' and the 'tenplate':

Code: Select all

function DetailsComprobantes_init_child (& $ options, $ memberInfo, & $ args) {
                
                foreach ($options as $x => $a) {
                    $options[$x]['template'] = 'children-DetailsComprobantes_new';
                    $options[$x]['records-per-page'] = '3';
                }
                
return TRUE;
}
in $ options, comes the array of values, the rest is equal to the normal function tablename_init of the hook.
I hope it serves.
Any doubt I remain available.