mevdschee / php-crud-ui

Single file PHP script that adds a UI to a PHP-CRUD-API project
MIT License
123 stars 55 forks source link

Help Needed: Running a function for a specific table #13

Closed anushaath closed 7 years ago

anushaath commented 7 years ago

Hi,

I want to call a function, every time there is an entry in the table. I've to call this function to send SMS on every booking entry.

So ideally I've to call this function whenever the record is added. My question is on which function(which acts as adding the record) do we call my SMS function (insertRecord() or addRecord())? And how do I know that I'm calling this function for the insertion of data in that specific table only?

For example, how do I know that I'm calling the SMS function only for insertion in the booking table and not calling it for any other table?

anushaath commented 7 years ago

I want to put the data submitted into an array, so that I can use it inside the functions. I'm confused as in where the SMS-sending function should exist. In the UI.php or api.php file?

anushaath commented 7 years ago

And also I want to block the text field if it is of type TIMESTAMP, just like how you blocked it for primary key. How do I do that?

mevdschee commented 7 years ago

I'm confused as in where the SMS-sending function should exist. In the UI.php or api.php file?

You should do this in the "api.php" file specifically in the "table_authorizer".

And how do I know that I'm calling this function for the insertion of data in that specific table only?

Look at the "$tab" parameter.

I want to block the text field if it is of type TIMESTAMP

You may use the "column_authorizer" to block certain columns.

anushaath commented 7 years ago

You mean the applyTableAuthorizer()?

I was planning to write this:

if ($tables =='booking') { $query=mysqli_query("SELECT package,customer_id FROM $tables"); sendSMS($query[package], $query[customer_id]); }

Will this definitely select the record which is being inserted/ the last record?

mevdschee commented 7 years ago

If you need the inserted data you could add your code to the function "createObject($input,$tables)":

https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1324

If the "insertId" is returned you know that the object will be created (unless a transaction fails).

mevdschee commented 7 years ago

Closed due to inactivity.