Editor PHP
Editor PHP

in DataTables 2
You have a discussion of the working of the Editor PHP libraries at https://editor.datatables.net/manual/php/getting-started
For several years, I have thought of using straight SQL, but I have not found a comprehensive discussion of how it might be done. For example, exactly how do I pass the (four??) required parameters--beginning record, number of records, etc.
Are there any pointers that you can share? Links?
Thanks!
Answers
When you say "straight SQL" - you'll need to explain that a little more I'm afraid. The client-side doesn't submit SQL for the server to execute - that would be a horrendous security hole.
I'm going to assume you have a an environment at the server-side, such as PHP, and want to take the data submitted from the client-side, build your own SQL statements based on that (make sure you do validation as well!) and execute it.
Based on that assumption, take a look at this page. It documents the client / server data interchange that Editor uses and with the information there you will be able to implement your own server-side code.
Happy to answer any questions you might have about it.
Allan
Hi Allan,
Thank you! That is what I was looking for. It is probably a lot of work; who knows if I'll get to it.
It can be simple for specific use cases - if you know what is coming in, it is easy to expect those variables. It is when you start handling dynamic options (e.g. multiple different forms) that things start to get more interesting!
Allan
Interesting discussion, guys!
I have been replacing Editor's logic with my own SQL as well: But only partly, not completely! I wanted more flexibility without giving up on the advantages that Editor has.
Some use cases:
Making my log table user accessible I use Editor in read only mode, get the fields to be displayed by json_decoding the log entry and also massaging the result returned from the server by embedding my own SQL on "postGet" for example.
I also have quite many occasions where I have to return the format of an Mjoin from the server but the SQL behind it is much more complex than Editor's Mjoin method can handle. Occasionally I also have to make much more complex updates than Editor can handle and use my own SQL for that as well. I do this on "validatedEdit", "validatedCreate", "writeEdit", "writeCreate" etc.
@menashe
If you need examples for such a "hybrid" approach, just let me know.
Roland
Roland,
Thank you! I would love to see examples.
I am very proficient in SQL, but I am "stuck" on how it would be "wrapped" to send the required information to the server. Any help is greatly appreciated. **
No problem. I can share something.
If you want to use your own SQL it is critical to find the right "hooks" i.e. event handlers, getFormatters etc., to insert the SQL.
Here is an example that is part of my solution to implement soft deletion. I think @allan supports this by now; so this is my own solution that I built without knowing about Allan's solution for this. But it should only serve as an example on how to insert your own SQL, I guess.
Soft deletion is actually editing, not removing rows. Hence the event handlers on the server are "validatedEdit", "writeEdit" and "postEdit" (and for completenes "writeCreate").
This is what I do:
"validatedEdit"
I find out whether the user attempts to delete any files by comparing them with what is saved in the database. File deletions may not be done physical but only logical with soft deletion. But: Editor will delete the link table to the file when a user deletes it. I need to mitigate that.
I use a SELECT statement to read the database using Editor's "raw" method. But you could also use your own db-handler for this.
Eventually I save any deleted files in a session variable $_SESSION['deletedFiles'] because I can't pass them to the next event handler. But no problem to use a session variable.
Then I make another SELECT to figure out whether this is a recovery situation (i.e. the undoing of a soft deletion) etc..
On "postUpload" and "postCreate" I only write the log using a helper function that also uses SQL. In this case it uses Editor's "insert" method but of course you could use plain SQL as well using the "raw" method or using your own db-handler.
On "writeCreate" and "writeEdit" I make additional manipulations using SQL helper functions before the data is read back from the server.
Then on "writeEdit" (after making the db-updates but before data is being read back from the server) I make additional db-updates so that Editor reads back the stuff I want it to read from the server. Here I use "raw" SQL but also Editor's "insert" and "update" methods. At the bottom you see "raw" method code commented out. This code would do the same as Editor's "update" method above it.
This is the code. I also added the helper functions called below. It is not particularly "elegant" but it can show you what you can do using those Editor event handlers.
And the helper functions:
Here is a getFormatter returning the same format as an Mjoin. As you can see I alias the column to pass in the value I need for selection and return the result under a different name in the "Mjoin"-format. Here I use my own db-handler and invoke it using "global".