Johan Broddfelt

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
'; foreach ($fields as $t) { $name = $t->varName; $code .= ' '; } $code .= '
'; if (preg_match("/_id$/", $t->columnName, $matches)) { $columnArr = explode('-', $t->columnName); $code .= ' ' . Db::realClassName(str_replace('_id', '', $columnArr[0])) . ' '; } else { $code .= ' ' . Db::realClassName($t->columnName) . ' '; } $code .= ' '; if ($t->columnName == 'id') { $code .= ' ' . $name . '; ?> '; } else if (preg_match("/_id$/", $t->columnName, $matches)) { $columnArr = explode('-', $t->columnName); if (count($columnArr) < 2) { $columnArr[1] = $t->columnName; } $table = preg_replace("/_id$/", '', $columnArr[1]); $objClassName = preg_replace('/s/', '', '' . $obj->className($table)); $sc = new $objClassName(); //print $table.' : '.$objlassName; $scFields = $sc->fetchFields(); $code .= ' fetchArray(' ORDER BY `' . $scFields[1]->columnName . '`, `id`'); ?> '; } else if ($t->realType == 'text') { $code .= ' '; } else { $code .= ' columnType == 'chk') { $code .= ' type="checkbox" value="1" ' . $name . ') { ?> checked="checked" '; } else { if (($t->realType == 'datetime' or $t->realType == 'timestamp')) { $code .= ' ' . $name . ' == '') { $obj->' . $name . ' = date('Y-m-d H:i:s'); } ?> '; } $code .= ' type="text" value="' . $name . '; ?>" '; } $code .= ' name="' . $t->columnName . '" '; if ($t->realType == 'date') { $code .= ' class="datepicker" '; } $code .= ' > '; } $code .= '
'; // 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

<< Edit on the fly
Follow using RSS
Delete post and Generic Class >>

Comment

Name
Mail (Not public)
Send mail updates on new comments
0 comment