/** * * @param string $action_name null if use default * @param array $params * @throws NotExistsException * @return string */ public static function generateURL($action_name = null, array $params = array()) { $default_action = Application::getApp()->getDefaultAction(); if ($action_name == null) { $action_name = $default_action; } $route = Route::getInstance(); $routes = $route->get('routes'); $path = array_search(strtolower($action_name), $routes); if (!$path) { throw new NotExistsException('Can not find the path', $action_name); } $main_server = Config::getInstance()->get('main_server'); if (strcasecmp($default_action, $action_name) == 0 && empty($params)) { if (empty($params)) { return $main_server; } else { $path = ''; } } $base = $path; $p = array(); foreach ($params as $key => $value) { if (is_int($key)) { $base .= '/' . $value; } else { $p[] = urlencode($key) . '=' . urlencode($value); } } $base = rtrim($base, '/'); if ($base) { if (Config::getInstance()->get('app.seo.ext')) { $base .= '.' . Config::getInstance()->get('app.seo.ext'); } } if (count($p)) { $base .= '?' . implode('&', $p); } return $main_server . ltrim($base, '/'); }
/** * * @param string $name * @return Ambigous <\ORC\MVC\Action, unknown>|NULL */ protected function _retrieveAction($name) { list($module_name, $action_name) = $this->_parseName($name); $class_name = sprintf('%s_%s_Action', $module_name, str_replace('.', '_', $action_name)); if (!class_exists($class_name)) { $found = false; $filename = DIR_APP_MODULE_ROOT . DIRECTORY_SEPARATOR . $module_name . DIRECTORY_SEPARATOR . 'actions' . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $action_name) . '.action.php'; //var_dump($filename);exit(); if (file_exists($filename)) { include_once $filename; $found = true; } else { //try to find from route table $actions = Route::getInstance()->getAllActions(); foreach ($actions as $action) { if ($module_name == $action['module']['name'] && $action_name == $action['name']) { $filename = $action['filepath']; if (file_exists($filename)) { include_once $filename; $found = true; } } } } if (!$found) { if ($module_name == 'default') { $filename = DIR_ORC_ROOT . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'actions' . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $action_name) . '.action.php'; if (file_exists($filename)) { include_once $filename; $found = true; } } } } if (class_exists($class_name)) { $class = new $class_name($this); if ($class instanceof \ORC\MVC\Action) { return $class; } } return null; }