Пример #1
0
 public function generateSql()
 {
     $namespace = \Zule\Tools\Config::zc()->framework->application_namespace;
     $system = 'Zule';
     $tables = $this->settings->getTables();
     foreach ($tables as $table) {
         $s = new \Smarty();
         $tableName = $table->getName();
         // generate model
         $s->assign('model_name', $_POST["class_{$tableName}"]);
         $s->assign('namespace', $namespace);
         $s->assign('system', $system);
         $s->assign('class_name', $_POST["class_{$tableName}"]);
         $s->assign('extend_path', '\\Zule\\Models\\Model');
         $s->assign('impl_date', date('Y-m-d H:i:s'));
         $s->assign('use_unsafe_setters', 0);
         $s->assign('table_name', $tableName);
         $columns = $table->getColumns();
         $s->assign('columns', $columns);
         $s->assign('primary_key', $table->getPrimaryKey());
         $gen = new Generator("../models/" . $_POST["class_{$tableName}"] . '.php');
         $gen->generate($s, 'model_sql');
         $gen = new Generator("../models/Data/" . $_POST["class_{$tableName}"] . '.php');
         $gen->generate($s, 'gateway_sql');
     }
 }
Пример #2
0
        $l[0] = strtoupper($l[0]);
        $name = $f . $l;
    }
    return $name;
}
function lCamel($name)
{
    while ($pos = strpos($name, '_')) {
        $f = substr($name, 0, $pos);
        $l = substr($name, $pos + 1);
        $l[0] = strtoupper($l[0]);
        $name = $f . $l;
    }
    return $name;
}
$namespace = \Zule\Tools\Config::zc()->framework->application_namespace;
$system = 'Zule';
$db = \Zule\Tools\DB::zdb();
$dbTables = $db->listTables();
foreach ($_POST as $table => $useless) {
    if (in_array($table, $dbTables)) {
        echo "Generating model file for {$table}" . PHP_EOL;
        // $table is scheduled for generation
        $s = new \Smarty();
        $model = $_POST["class_{$table}"];
        $s->assign('model_name', $model);
        $s->assign('namespace', $namespace);
        $s->assign('system', $system);
        $s->assign('php_open', '<?php');
        $columns = [];
        $camels = [];
<?php

require_once '../tools/Loader.php';
$s = new Smarty();
$namespace = \Zule\Tools\Config::zc()->framework->application_namespace;
$system = 'Zule';
$controller = $_POST['name'];
$addActions = explode(',', $_POST['actions']);
if (isset($_POST['make_index'])) {
    $acts = [\Zule\Tools\Config::zc()->framework->index_action];
} else {
    $acts = [];
}
$acts = array_merge($acts, $addActions);
if (isset($_POST['make_views'])) {
    $s->assign('generateViews', 1);
} else {
    $s->assign('generateViews', 0);
}
$s->assign('actions', $acts);
$s->assign('actionString', '\'' . implode('\',\'', $acts) . '\'');
$s->assign('open_php', '<?php');
$s->assign('namespace', $namespace);
$s->assign('system', $system);
$s->assign('controller', $controller);
echo '<pre>';
echo 'Generating controller template...' . PHP_EOL;
$string = $s->fetch('new_controller.tpl');
echo 'Controller template created' . PHP_EOL;
$destFile = "../controllers/{$controller}.php";
$fh = fopen($destFile, 'x');