Programatically add a function to an AppGini's generated file.

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
hernan
Posts: 17
Joined: 2020-06-22 18:56

Programatically add a function to an AppGini's generated file.

Post by hernan » 2021-04-15 20:45

Hi all,

I'm trying to keep the generated code from AppGini as clean as possible. I made a lot of /hooks/ customization and all, but I needed to modify some functions in the generated code.

I followed the recipe from Genedy regarding "Overwriting AppGini functions...https://bigprof.com/blog/appgini/custom ... dmin-area/ " and I managed to make it work! 8-)

But now, instead of replacing a function, I would like to add a function into an AppGini automatically generated file.

For example I want to add a custom function to incCommon.php file.
I tried to modify the code to replace functions, but my PHP knowledge is not enough, so I don't know how to "append" something to a php file from a php script.

So I came here looking for enligthnment!
  • First: does anyone know how this can be done, to attach a function to a php file from a php script?
  • Second: does it makes sense to wanting to add a function to incCommon.php, or is there other way to make a custom function accesible from incCommon.php without adding the function into the file but keeping it in a separate file?

Background information:
Currently working with 5.95 revision 1136, because since I'm changing things, let's do it with the latest version...

I'm trying to make my app as "future proof" as possible, and to have the ability to quickly create new fields and tables from AppGini, regenerate code and not having to spend hours manually reapplying all the modifications made to the code outside hooks.
Unfortunately the initial code was not created by me, it is quite messy and I just have to maintain the running application into the company I work for. And everytime a user asks me for a new functionality, or even a new field... i cry in despair thinking of the headaches that modification will cause due to all the customization of AppGini files :D

So, any help will be greatly appreciated!

Have a nice day!

hernan
Posts: 17
Joined: 2020-06-22 18:56

Re: Programatically add a function to an AppGini's generated file.

Post by hernan » 2021-04-15 21:14

NEVERMIND! I did it!

I just needed to add the "FILE_APPEND" mode to file_put_content...!

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 1308
Joined: 2018-04-01 10:12

Re: Programatically add a function to an AppGini's generated file.

Post by pböttcher » 2021-04-17 07:20

Hi,
just for curiosity. Why do you need to add a custom function to ncCommon.php? There are so many placed where you can add you custom function and it will be available (hooks/header-extras.php, hooks/footer-extras.php, hooks/__global.php, ....). And those files do not get overwritten.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1152
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Programatically add a function to an AppGini's generated file.

Post by jsetzer » 2021-04-17 09:45

+1 @pböttcher

Additionally, there is the NEW magic file hooks/__bootstrap.php which will be loaded at the very beginning. Caution: this will be loaded even before lib.php, so don't expect existence of well known AppGini PHP functions at that point.
Kind regards,
<js />

hernan
Posts: 17
Joined: 2020-06-22 18:56

Re: Programatically add a function to an AppGini's generated file.

Post by hernan » 2021-04-19 09:25

pböttcher:
This function add a variable to SESSION, and in the function htmlUserBar() (from incCommon.php ) I call this custom function.
It's a selector of environment.. we have people working for different areas, but on the same db, and some users can select what area they want to see (like managers).

It's probably possible to add it in hooks/header-extras.php, yes... I will try that. Thanks for the tip!
As I said the code was kind of inherited to me.

jsetzer :
I will check that hooks/__bootstrap.php magic file.
I'll look into the documentation so I can be sure if it can help for this purpose.

Thank you both!

Post Reply