A Content Engine Generator
As the above sections states a lot of the functionality of the Content Engine can be accomplished in a generic and programmatic way. However the implementation of each function of the content server is long-winded and tedious. So why not generate most of the content engine. This is where PHP again proves to be a natural.
Rather then generating HTML from PHP code we can generate PHP code from PHP code ?? if you know what I mean :). To illustrate how simple this is the following is PHP/pseudo-code code-snippet to generate the “get by id” and “get list by criteria” functions for your schema: (NOTE: you don??t have to give too much attention to the code itself but notice that the code represented in “red” is what will be generated and other colors represent the generator itself.)
<?php
//get all table description in your schema
for ($i=0; $i < count($tables); $i++) {
$table_name = $tables[$i];
$column_names = getColumnNames($db_name, $table_name, $conn);
$nmcengine.="
function get_$table_name($$column_names[0]) {
$query="SELECT * FROM $table_name WHERE $column_names[0]=$$column_names[0]";
global $conn;
return get_element('$table_name', $conn, $query);
}
function get_{$table_name}_list($$table_name) {
$xpath = new XPath();
$xpath->importFromString($$table_name);
$query="SELECT * FROM $table_name";
$clause_count=0;n"
;
for($j=0;$j < count($column_names);$j++) {
$nmcengine.="
$value=interpret_result($xpath->getData('/$table_name/$column_names[$j]'));
nextClause($query, $value,$clause_count, '$column_names[$j]');";
}
$nmcengine.="
global $conn;
$result = get_element_list('{$table_name}_list', '$table_name', $conn, $query);
return displayArray($result);
}
";
?>