Beispiel #1
0
function display_model_generate_wizard()
{
    global $db;
    clear_terminal();
    echo wrap_output(sprintf(__(YZE_METHED_HEADER . "\n\n你将生成Model代码,请根据提示进操作,%s返回上一步:\n1. (1/2)表名: "), "生成Model代码结构", get_colored_text(" 0 ", "red", "white")));
    while (!is_validate_table($table = get_input())) {
        echo get_colored_text(wrap_output(sprintf(__("\t表不存在(%s),请重输:  "), mysqli_error($db))), "red");
    }
    echo wrap_output(__("2. (2/2)所在module模块名,  遵守PHP变量命名规则:  "));
    while (!is_validate_name($module = get_input())) {
        echo get_colored_text(wrap_output(__("\t功能模块名,  请重输:  ")), "red");
    }
    $model = rtrim($table, "s");
    if (class_exists("\\app\\{$module}\\{$model}_Model")) {
        echo wrap_output(__("\\app\\{$module}\\{$model}_Model 已存在,继续操作将覆盖已有文件:  \n\t1.  继续\n\t2.  返回\n"));
        while (!in_array($input = fgets(STDIN), array(1, 2))) {
            echo wrap_output(__("请选择操作对应的序号: "));
        }
        switch ($input) {
            case 1:
                return array("cmd" => "model", "base" => "table", "module_name" => $module, "class_name" => $model, "table_name" => $table);
            case 2:
                display_home_wizard();
                return;
            default:
                return array();
        }
    }
    return array("cmd" => "model", "base" => "table", "module_name" => $module, "class_name" => $model, "table_name" => $table);
}
Beispiel #2
0
 protected function get_class_of_table($table)
 {
     global $db;
     $class_name = YZE_Object::format_class_name(rtrim($table, "s"), "Model");
     if (class_exists($class_name)) {
         return $class_name;
     }
     if (@self::$chain_tables[$table]) {
         //之前已经处理过了
         return self::$chain_tables[$table];
     }
     clear_terminal();
     echo wrap_output(sprintf(__("    ================================================================\r\n\t\t\r\n    未能识别关联表%s的Model类,请输入该类所在的module名(默认当前模块):"), $table));
     $module = get_input();
     if (!$module) {
         $module = $this->module_name;
     }
     self::$chain_tables[$table] = $module;
     if (class_exists("\\app\\{$module}\\{$class_name}")) {
         return "\\app\\{$module}\\{$class_name}";
     }
     echo get_colored_text(wrap_output(sprintf(__("    开始生成 %s..."), "\\app\\{$module}\\{$class_name}")), "blue", "white") . "\r\n";
     $object = new \yangzie\Generate_Model_Script(array("cmd" => "model", "base" => "table", "module_name" => $module, "class_name" => preg_replace('/_model$/i', "", $class_name), "table_name" => $table));
     $object->generate();
     echo "\r\n" . get_colored_text(wrap_output(sprintf(__("    生成结束 %s ."), "\\app\\{$module}\\{$class_name}")), "blue", "white") . "\r\n";
     return "\\app\\{$module}\\{$class_name}";
 }