/** * URL组装,兼容各种路由模式 * * @param string $url 如:admin://system/msg/send/username/args2 或者 system/msg/send/username/args2 * @param array $params 参数 * @param string $fragment 锚点名称或者框架名称 * @return string 完整的url */ public static function build($uri, $params = array(), $fragment = '') { $uri = trim($uri, '/'); //去掉开头结尾的 / 符号,或者去掉分隔符 if (strpos($uri, '://') === false) { $uri = router::application() . '://' . $uri; } $uris = parse_url($uri); $paths = explode('/', trim($uris['path'], '/')); $urls = array(); $urls['base'] = $uris['scheme'] == router::application() ? url::base() : application::settings($urls['scheme'], 'base'); $urls['module'] = $uris['host']; $urls['controller'] = $paths[0]; $urls['action'] = $paths[1]; //zotop::dump($urls); if (zotop::config('zotop.url.model') == 0) { } else { $url = $urls['base']; if (zotop::config('zotop.url.model') == 2) { $url = $url . '?zotop='; //开启兼容模式 } $url = $url . '/' . $urls['module'] . '/' . $urls['controller'] . '/' . $urls['action']; if (!empty($params)) { foreach ($params as $key => $value) { $url .= '/' . $value; } } } if (!empty($fragment)) { $url .= '#' . $fragment; } return url::clean($url); }
public function getTemplatePath($action = '') { if (empty($this->template)) { if (empty($action)) { $action = application::getAction(); } $module = application::getModule(); $controller = application::getController(); $path = zotop::module($module, 'path'); $path = $path . DS . router::application() . DS . 'template' . DS . $controller . DS . $action . '.php'; return $path; } return $this->template; }
/** * 获取当前的控制器的相关信息 * * @return string */ public static function controller($type = 'name') { switch ($type) { case 'name': case 'filename': $return = empty(self::$controller) ? 'index' : self::$controller; break; case 'path': case 'filepath': $return = module::setting(Router::module(), 'root') . DS . router::application() . DS . router::controller('filename') . '.php'; break; case 'class': case 'classname': $return = empty(self::$controller) ? 'IndexController' : ucfirst(self::$controller) . 'Controller'; break; } return $return; }
public static function controllerPath() { $controller = router::controller(); if ($controller) { return zotop::module(router::module(), 'root') . DS . router::application() . DS . router::controller() . '.php'; } return ''; }
/** * 返回当前的控制器的真实路径 * * @return string */ public static function getControllerPath() { $controller = application::getController(); $module = application::getModule(); $path = zotop::module($module, 'root') . DS . router::application() . DS . $controller . '.php'; return $path; }
/** * 返回当前的控制器的真实路径 * * @return string */ public static function getControllerPath() { $controller = application::getController(); $module = application::getModule(); $path = zotop::module($module, 'path'); if (empty($path)) { zotop::error(array('title' => '系统错误', 'content' => zotop::t('<h2>未能找到相应模块,请检查模块是否未安装或者已被禁用?</h2>模块名称:{$module}', array('module' => $module)))); } $path = $path . DS . router::application() . DS . $controller . '.php'; return $path; }