public static function loadRoute($route) { // run this method only one time if (!self::$can_run) { return; } self::$can_run = false; $__r_controller = $route['controller']; $__r_action = $route['action']; $__r_params = $route['params']; self::$controller = $__r_controller; $__r_file = Environment::get('Application.controllers') . '/' . $__r_controller . '.php'; if (file_exists($__r_file) == false || is_readable($__r_file) == false) { if (self::$debug) { throw new Exception("Invalid controller file: {$__r_file}"); } else { call_user_func(self::$error404); } } else { include_once $__r_file; $__r_class = $__r_controller . 'Controller'; if (class_exists($__r_class)) { $__r_object = new $__r_class(); if (is_callable(array($__r_object, $__r_action)) == false) { $__r_action = 'index'; } self::$action = $__r_action; call_user_func_array(array($__r_object, $__r_action), $__r_params); } else { throw new Exception("Invalid class: {$__r_class}"); } } }
public static function action($action = 'index', $params = array()) { if (!isset($action)) { $action = 'index'; } if (!isset($controller)) { $controller = Application::controller(); if (!isset($controller)) { $controller = 'index'; } } $url = self::url() . "/{$controller}/{$action}"; foreach ($params as $param) { $url .= "/{$param}"; } return $url; }
/** * Run dispatch process. * * @return mixed */ protected function dispatch() { Hook::event("PreDispatch"); $controllerName = Core::getRequest()->getGET("controller", "index"); $package = Core::getRequest()->getGET("package", DEFAULT_PACKAGE); $overridePackage = null; if (strpos($controllerName, ".")) { list($overridePackage, $controllerName) = explode(".", $controllerName); } self::$controllerName = $controllerName; $config = array("action" => Core::getRequest()->getGET("action", "index")); $class = ($overridePackage !== null ? $overridePackage : $package) . "/controller_" . lcfirst($controllerName); self::$controller = self::factory($class, $config); if (!self::$controller) { self::$controller = self::factory($package . "/controller_index", array("action" => "noroute")); } Hook::event("PostDispatch"); return self::$controller->run(); }