Generating the edit form
You did not think that we would leave the edit form without a code generator, did you? Of course we need to generate a php-file so that we can modify the code of the edit.php as well. The same strategy applies as for the list.php. So here we go. Create the file views/generic/edit_code.php
fetchFields();
$colCount = count($fields);
$code =
'varName;
if ($t->columnName == 'id') {
// do nothing;
} else {
$code .=
' $obj->' . $name . ' = filter_input(INPUT_POST, '' . $f->columnName . '');
';
}
}
$code .=
' $obj->update();
?>
Changes are saved
id == 0) { ?>
New
Edit
' . $obj->realClassName() . '
Back
';
// Make dir if it does not exist. Named after $module
if (!is_dir('views/' . $module)) {
mkdir('views/' . $module);
}
$fh = fopen('views/' . $module . '/' . $view . '.php', 'w');
fwrite($fh, $code);
fclose($fh);
?>
File generated
Now you can type index.php?modue=[your_module]&view=edit&generate=code and the edit file will be generated along with the code that will be printed on the screen. Enjoy!
- framework, php, generic, software
Comment
0 comment