/** * forward<br/> * ex) $this->forward_to('/main/index/1'); * @see public/codeseed.php */ public function forward_to($where) { // parse path $path = parse_url_path($where); if (empty($path[1])) { $path[1] = Config::get('default_controller'); } if (empty($path[2])) { $path[2] = Config::get('default_action'); } $controller_path = $path[1]; $action_path = $path[2]; if (file_exists(Config::get('help_dir') . '/' . $controller_path . '.php')) { require_once Config::get('help_dir') . '/' . $controller_path . '.php'; } $controller_name = under_to_camel($controller_path . '_controller'); $controller = new $controller_name(); // reserve controller and action name $controller->controller_name = $this->controller_name; $controller->action_name = $this->action_name; // execute request call_user_func(array($controller, 'before_filter')); call_user_func_array(array($controller, $action_path), refine_params(array_slice($path, 3))); call_user_func(array($controller, 'after_filter')); if (file_exists(Config::get('view_dir') . '/' . $controller_path . '/' . $action_path . '.php')) { call_user_func_array(array($controller, 'load_view'), array($controller_path . '/' . $action_path)); } $this->skip(); }
public function get_contents() { $table = camel_to_under($this->name); $class = under_to_camel($this->name); $result = str_replace('<table>', $table, $this->template); $result = str_replace('<class>', $class, $result); return $result; }
public function get_contents() { $class = under_to_camel($this->name); $filename = camel_to_under($this->name); $functions = $this->get_functions_contents(); $result = str_replace('<class>', $class, $this->template); $result = str_replace('<filename>', $filename, $result); $result = str_replace('<functions>', $functions, $result); return $result; }
/** * make one result row to one object * @param $row - db result row * @param $tablename - table name * @return model object or relation model object */ private function make_object($row, $tablename) { $classname = under_to_camel($tablename); $obj = new $classname(); $has_property = false; foreach ($row as $column => $value) { if (is_int($column)) { continue; } $aliases = explode('__', $column); // if there is no virtual aliases... if (count($aliases) < 2) { $aliases[1] = $aliases[0]; $aliases[0] = $this->tablename; } $tablename_alias = $aliases[0]; if ($tablename_alias == $tablename) { $column_alias = $aliases[1]; $obj->{$column_alias} = $value; if (!is_null($value)) { $has_property = true; } } } if ($has_property) { return $obj; } return null; }
// read migration files... $files = get_files(Config::get('migr_dir')); if ($INTEND_VERSION >= $schema_version->version) { sort($files); $direction = 'UP'; } else { rsort($files); $direction = 'DOWN'; } for ($i = 0; $i < count($files); $i++) { $file = $files[$i]; $matches = Migration::parse_migration_filename($file); if (!empty($matches)) { $version = $matches[1]; $filename = $matches[2]; $classname = under_to_camel($filename); if ($direction == 'UP' && $version > $schema_version->version && $version <= $INTEND_VERSION) { // require_once($file); $migration = new $classname(); $migration->up(); $schema_version->version = $version; $schema_version->update(); print_migration_status($direction, $classname, $version); } if ($direction == 'DOWN' && $version <= $schema_version->version && $version > $INTEND_VERSION) { // require_once($file); $migration = new $classname(); $migration->down(); if ($i == count($files) - 1) { $down_version = 0; } else {
echonl("\t`php script/generate.php model User`"); echonl("\t`php script/generate.php migration AddPrice`"); echonl("\t`php script/generate.php controller Welcome login logout`"); exit(0); } // init array_shift($argv); $kind = $argv[0]; array_shift($argv); $name = $argv[0]; array_shift($argv); $params = $argv; if (!file_exists(Config::get('plugin_classes') . '/generator/' . $kind . '_generator.class.php')) { echonl("No " . $kind . ' generator exist.'); exit(0); } try { $classname = under_to_camel($kind) . 'Generator'; $generator = new $classname($name, $params); $generator->generate(); } catch (Skip $e) { Context::get('db')->rollback(); } catch (DbError $e) { Context::get('db')->rollback(); Log::error($e->getMessage()); echonl($e->getMessage()); } catch (Exception $e) { Context::get('db')->rollback(); Log::error($e->getMessage()); echonl($e->getMessage()); }
* @see Controller.forward_to() */ // parse path $path = parse_url_path(_server('PATH_INFO')); if (empty($path[1])) { $path[1] = Config::get('default_controller'); } if (empty($path[2])) { $path[2] = Config::get('default_action'); } $controller_path = $path[1]; $action_path = $path[2]; if (file_exists(Config::get('help_dir') . '/' . $controller_path . '.php')) { require_once Config::get('help_dir') . '/' . $controller_path . '.php'; } $controller_name = under_to_camel($controller_path . '_controller'); $controller = new $controller_name(); // set action name $controller->controller_name = $controller_name; $controller->action_name = $action_path; // execute request call_user_func(array($controller, 'before_filter')); call_user_func_array(array($controller, $action_path), refine_params(array_slice($path, 3))); call_user_func(array($controller, 'after_filter')); if (file_exists(Config::get('view_dir') . '/' . $controller_path . '/' . $action_path . '.php')) { call_user_func_array(array($controller, 'load_view'), array($controller_path . '/' . $action_path)); } } catch (Skip $e) { } catch (DbError $e) { Log::error($e->getMessage()); // TODO replace below