Customizing datatables php scripts on the fly
Customizing datatables php scripts on the fly
Datatables generator has created php scripts which I'm attempting to customize. The code segment below was created in table.applications.php and tells editor which fields to use
Editor::inst( $db, 'applications', 'appid' )
->fields(
->fields(
Field::inst( 'appname' ),
Field::inst( 'appdesc' )
)
->process( $_POST )
->json();
I'm attempting to generate this code segment programmatically to allow me to easily adapt to changing table and form fields. So, I've attempted to iterate to create the field definitions using the following code:
$tablefields = array(
"appname",
"appdesc"
);
$editor_php_construct ="";
$arrlength = count($tablefields);
for($x = 0; $x < $arrlength; $x++) {
$editor_php_construct .= "Field::inst( '".$tablefields[$x]."')";
if ($x+1 < $arrlength) {
$editor_php_construct .= ",";
} else {
$editor_php_construct .= ")";
}
}
Running this code gives me the equivalent of
Field::inst( 'appname' ),
Field::inst( 'appdesc' )
How can I incorporate $editor_php_construct into the script and evaluate it?
Thanks in advance for your help.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
You wouldn't construct the string version of the PHP since you'd need to then evaluate that. I guess you could write it into a file and then PHP include it, but that would seem like a significant security risk and processing overhead to me.
Instead simply do:
Allan
Thank you so very much Alan. Really appreciate your responsiveness and expertise.