#native_company# #native_desc#

PHP, XML, XSL, XPATH and Web Services Page 5

By Mashooq Badar
on May 6, 2004

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.)


//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);
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();
    $query="SELECT * FROM $table_name";
$j=0;$j count($column_names);$j++) {
    nextClause($query, $value,$clause_count, '$column_names[$j]');"
    global $conn;
    $result = get_element_list('{$table_name}_list', '$table_name', $conn, $query);
    return displayArray($result);