Insert a record via hook.

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
arcanebits
Veteran Member
Posts: 104
Joined: 2018-12-10 21:52

Insert a record via hook.

Post by arcanebits » 2023-10-24 14:41

Before asking, I search the web as best I can and run tests until I simply can't find anything. I have a code, and it works in the sense that it adds the field and I can see it from myphp admin, but it doesn't show up in the application and on top of that, it breaks the web page with an error. I'm pretty sure it's not only rudimentary but that I'm probably not using the right function.
The error: This page isn’t working right now

$prueba=sqlValue("INSERT INTO tareas (cip, nomb1, ape1, detalle, fechaini, comentario, fechafinal, estado, image, minuesti, tipo) SELECT cip, nomb1, ape1, 'My Tarea automatica', DATE_ADD(fechaini, INTERVAL 2 DAY), comentario, fechafinal, estado, image, minuesti, tipo FROM tareas ORDER BY fechaini DESC LIMIT 1;");

Doing baby steps, here, first I need to fully manualy add hard coded record, then the hard code its going to change to another record with some specification

My goal its to learn the best way to add a record via hooks and to it be supported/visible on the appgini app

Hope to hear any help
a3

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

Re: Insert a record via hook.

Post by jsetzer » 2023-10-24 14:53

I can see it from myphp admin, but it doesn't show up in the application
Perhaps you did not set the owner?

Code: Select all

set_record_owner('TABLENAME', $THE_NEW_PRIMARY_KEY);
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

arcanebits
Veteran Member
Posts: 104
Joined: 2018-12-10 21:52

Re: Insert a record via hook.

Post by arcanebits » 2023-10-24 15:16

Thanks! I will check that right away. The function im using its the correct one? Im doing it right?
A3

arcanebits
Veteran Member
Posts: 104
Joined: 2018-12-10 21:52

Re: Insert a record via hook.

Post by arcanebits » 2023-10-25 14:41

Update: Made it appear, raise one question.

First task is related to the Permission issue, so I went to "Membership_userrecords" and cloned the last working record with PKValue poiting to my tareas.id record.

It worked, but this raises a question, is there a function im missing here? I mean Appgini create records and stuff internaly and I went full(almost) manualy to add a record. Dont think I will need to create two records on two diferent tables to make this work (add a single record)

Still learning but doing my best, thanks for all help im getting.
A3

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

Re: Insert a record via hook.

Post by jsetzer » 2023-10-25 16:55

I'm not sure if I got your question completely.

Whenever you create a record in AppGini UI and you leave _after_insert hook returning TRUE, AppGini automatically inserts the membership_userrecord entry. That entry brings the new record under access control.

Whenever YOU create a new record in database, using SQL commands or any other database tool, you will have to create that record. To make it easy, AppGini provides the set_record_owner function I have mentioned above.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

arcanebits
Veteran Member
Posts: 104
Joined: 2018-12-10 21:52

Re: Insert a record via hook.

Post by arcanebits » 2023-10-26 13:20

Ohh I understand completely now!

Thanks a lot that really helped my understanding!

One last question befere closing this (already answered thread), where can i dig information on all of the Appgini Functions as this one, so I can go and read the manual?

Thanks again!
a3

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

Re: Insert a record via hook.

Post by jsetzer » 2023-10-26 13:57

Well, in the beginning I've taken the UDEMY courses. Now, on every new version, I study the changelog and check out a couple of important PHP files, looking for interesting functions which I might need in the future:
  • incFunctions.php
  • incCommon.php
Also, I go to developer tools in my browser and type AppGini. and check if there are any new javascript functions in AppGini object.

Beyond that, the only thing that helps is reading, comprehending, understanding, trying, making mistakes, finding and improving errors, trying again.

Me, too, in the beginning I had to learn it the hard way when inserting records into tables using SQL commands and not finding the records in UI. At that time I had to check and understand the membership_* tables and also read the code which runs especially before, in between and after _before_* and _after_*-hooks.

Last but not least I'm reading this forum almost every day, trying to understand, learn, answer questions, propose solutions and trying to get better every day.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

arcanebits
Veteran Member
Posts: 104
Joined: 2018-12-10 21:52

Re: Insert a record via hook.

Post by arcanebits » 2023-10-27 12:35

Thank you a LOT, you just gave me some pieces of info that I know took you a lot of time by yourself, much appreciated!
I will take all that into account.
Aldo

Post Reply