public function set_module($module) { $this->module = $module; $this->module_class = YZE_Object::format_class_name($module, "Module"); if (class_exists($this->module_class)) { $this->module_obj = new $this->module_class(); return $this; } $class = "\\app\\" . $module . "\\" . $this->module_class; if (class_exists($class)) { $this->module_obj = new $class(); } return $this; }
private function create_controller($controller) { $module = $this->module_name; $class = YZE_Object::format_class_name($controller, "Controller"); $class_file_path = dirname(dirname(__FILE__)) . "/app/modules/" . $module . "/controllers/" . strtolower($class) . ".class.php"; $class_file_content = "<?php\r\nnamespace app\\{$module};\r\nuse \\yangzie\\YZE_Resource_Controller;\r\nuse \\yangzie\\YZE_Request;\r\nuse \\yangzie\\YZE_Redirect;\r\nuse \\yangzie\\YZE_Session_Context;\r\nuse \\yangzie\\YZE_RuntimeException;\r\nuse \\yangzie\\YZE_JSON_View;\r\n\r\n/**\r\n*\r\n* @version \$Id\$\r\n* @package {$module}\r\n*/\r\nclass {$class} extends YZE_Resource_Controller {\r\n public function index(){\r\n \$request = \$this->request;\r\n //\$this->layout = 'tpl name';\r\n \$this->set_view_data('yze_page_title', 'this is controller " . $this->controller . "');\r\n }\r\n\r\n public function exception(YZE_RuntimeException \$e){\r\n \$request = \$this->request;\r\n \$this->layout = 'error';\r\n //处理中出现了异常,如何处理,没有任何处理将显示500页面\r\n //如果想显示get的返回内容可调用 :\r\n \$this->post_result_of_json = YZE_JSON_View::error(\$this, \$e->getMessage());\r\n //通过request->the_method()判断是那个方法出现的异常\r\n //return \$this->wrapResponse(\$this->yourmethod())\r\n }\r\n}\r\n?>"; echo __("create controller:\t\t"); $this->create_file($class_file_path, $class_file_content); if ($this->view_format) { $this->create_view(); $this->create_layout(); } }
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}"; }