/** * 应用程序执行 * * * @return null */ public static function run() { $className = application::getControllerName(); $classPath = application::getControllerPath(); $method = application::getControllerMethod(); $arguments = router::arguments(); //加载controller if (file_exists($classPath)) { zotop::load($classPath); } else { zotop::run('system.404', array('filepath' => $classPath)); return false; } if (class_exists($className, false)) { $controller = new $className(); if (method_exists($controller, $method) && $method[0] != '_') { call_user_func_array(array($controller, '__before'), $arguments); call_user_func_array(array($controller, $method), $arguments); call_user_func_array(array($controller, '__after'), $arguments); return true; } //当方法不存在时,默认调用类的_empty()函数,你可以在控制器中重写此方法 return call_user_func_array(array($controller, '__empty'), array($method, $arguments)); } return false; }
public static function execute() { if ($uri = trim(router::$uri, '/')) { router::$arguments = explode('/', $uri); router::$module = array_shift(router::$arguments); router::$controller = array_shift(router::$arguments); router::$action = array_shift(router::$arguments); } else { //当$uri 为空,则尝试Query_string模式 router::$arguments = $_GET; router::$module = arr::take('module', router::$arguments); router::$controller = arr::take('controller', router::$arguments); router::$action = arr::take('action', router::$arguments); } }
/** * 解析URI * * URI 由模块名/控制器/动作/参数组成,采用如下的格式: * * @code php * module/controller/action/param1/param2 * @endcode * */ public static function execute() { $u = explode('/', trim(router::$uri, '/')); //获取namespace 和 arguments $namespace = implode('/', array_slice($u, 0, 3)); $arguments = array_slice($u, 3); $namespace = zotop::filter('zotop.namespace', $namespace, &$arguments); if ($namespace) { list(router::$module, router::$controller, router::$action) = explode('/', $namespace); } //处理参数 for ($i = 0, $cnt = count($arguments); $i < $cnt; $i++) { $arguments[$i] = rawurldecode($arguments[$i]); } router::$arguments = $arguments; }
/** * 应用程序执行 * * * @return null */ public static function run() { $classname = router::controllerName(); $filepath = router::controllerPath(); $method = router::controllerMethod(); $arguments = router::arguments(); //加载controller if (file_exists($filepath)) { zotop::load($filepath); } if (class_exists($classname, false)) { $controller = new $classname(); if (method_exists($controller, $method) && $method[0] != '_') { return call_user_func_array(array($controller, $method), $arguments); } else { //当方法不存在时,默认调用类的_empty()函数,你可以在控制器中重写此方法 return call_user_func_array(array($controller, '_empty'), $arguments); } } zotop::run('system.404', array('filepath' => $filepath)); }
/** * 解析URI * * URI 由模块名/控制器/动作/参数组成,采用如下的格式: * * @code php * module/controller/action/param1/vlaue1/param2/value2 * @endcode * */ public static function execute() { if ($uri = trim(router::$uri, '/')) { router::$arguments = explode('/', $uri); //分配module、controller、action router::$module = array_shift(router::$arguments); router::$controller = array_shift(router::$arguments); router::$action = array_shift(router::$arguments); //处理参数 $arguments = array(); for ($i = 0, $cnt = count(router::$arguments); $i < $cnt; $i++) { $arguments[$i] = rawurldecode(router::$arguments[$i]); } router::$arguments = $arguments; //unset($_GET['zotop']); //$_GET = array_merge($_GET, array('module'=>router::$module,'controller'=>router::$controller,'action'=>router::$action), $arguments); } else { //当$uri 为空,则尝试Query_string模式 router::$arguments = $_GET; router::$module = arr::take('module', router::$arguments); router::$controller = arr::take('controller', router::$arguments); router::$action = arr::take('action', router::$arguments); } }
public static function arguments() { return router::arguments(); }