protected function Create_Table($table = NULL) { if ($table !== NULL) { $tablName = $table['Table']; $query = "CREATE TABLE `" . $tablName . "` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,"; foreach ($table as $key => $Field) { if (strcmp($key, 'Table') != 0) { if ($Field['type'] == 'VARCHAR' and (!isset($Field['limit']) or $Field['limit'] == '')) { $Field['limit'] = 250; } $query .= (isset($Field['field']) and isset($Field['type'])) ? "`" . $Field['field'] . "` " . $Field['type'] : NULL; $query .= (isset($Field['limit']) and $Field['limit'] != '') ? " (" . $Field['limit'] . ")" : NULL; $query .= ($Field['type'] == 'VARCHAR' or $Field['type'] == 'TEXT' or $Field['type'] == 'LONGTEXT') ? ' CHARACTER SET utf8 COLLATE utf8_general_ci' : NULL; $query .= (isset($Field['null']) and $Field['null'] != '') ? " NOT NULL" : NULL; $query .= (isset($Field['default']) and $Field['default'] != '') ? " DEFAULT '" . $Field['default'] . "'" : NULL; $query .= " ,"; } } $query .= "created_at INT NOT NULL ,"; $query .= "updated_at INT NOT NULL "; $query .= ")CHARACTER SET utf8 COLLATE utf8_general_ci;"; $Ar = new NewAr(); $Ar->Connect(); $Ar->driver->exec($query); $Ar->WriteSchema($tablName); $Ar->WriteModel($tablName); } }
<? $arraux = (isset($arraux))? $arraux: NULL; $path=INST_PATH; $_POST['migrations'][$arraux['Table']] = 'on'; $_POST['migrations']['up:selected'] = true; $this->MigrationsActions(); $file = Singulars(strtolower($arraux['Table'])); // Creation of model $Obj = new NewAr(); $Obj->WriteModel($arraux['Table']); // Creation of the list view $ClassName = Camelize($arraux['Table']); $ClassToUse = Camelize(Singulars($arraux['Table'])); $directory = INST_PATH."app/templates/$file/"; if(!is_dir($directory)) mkdir($directory); $fp = fopen($directory.'index.phtml', 'w+b'); $content = '<div style="float:left; width:100%;">'."\n"; $content .= "\t".'<div align="center">'."\n"; $content .= "\t\t".'<table width="100%">'."\n"; $content .= "\t\t\t".'<? foreach($this->data as $row){ ?>'."\n"; $content .= "\t\t\t<tr>\n"; $content .= "\t\t\t".'<? foreach($row->getArray() as $col){ ?>'."\n"; $content .= "\t\t\t\t".'<td><?=$col;?></td>'."\n"; $content .= "\t\t\t<? } ?>\n"; $content .= "\t\t\t\t<td><a href=\"<?=INST_URI;?>$file/delete/<?=\$row->id;?>\">delete</a> <a href=\"<?=INST_URI;?>$file/addedit/<?=\$row->id;?>\">Edit</a></td>\n"; $content .= "\t\t\t</tr>\n"; $content .= "\t\t\t<? } ?>\n"; $content .= "\t\t</table>\n"; $content .= "\t</div>\n";