do domain merge support old code
Showing
1 changed file
with
30 additions
and
1 deletions
@@ -64,12 +64,41 @@ class Bootstrap extends Bootstrap_Abstract | @@ -64,12 +64,41 @@ class Bootstrap extends Bootstrap_Abstract | ||
64 | */ | 64 | */ |
65 | public function _initRoute(Dispatcher $dispatcher) | 65 | public function _initRoute(Dispatcher $dispatcher) |
66 | { | 66 | { |
67 | - $config = new Config\Ini(APPLICATION_PATH . '/configs/routes.ini'); | 67 | + /* 根据域名的级别,选择对应的模块 */ |
68 | + $hostParts = explode('.', $dispatcher->getRequest()->getServer('HTTP_HOST', '')); | ||
69 | + $level = count($hostParts) - 1; | ||
70 | + $module = 'Index'; | ||
71 | + // 三级域名 | ||
72 | + if ($level === 3) { | ||
73 | + switch (strtolower(strval($hostParts[0]))) { | ||
74 | + case 'm': | ||
75 | + case 'new': // 默认 | ||
76 | + $module = 'Index'; | ||
77 | + break; | ||
78 | + case 'guang': // 逛 | ||
79 | + $module = 'Guang'; | ||
80 | + break; | ||
81 | + case 'list': // 商品列表 | ||
82 | + $module = 'Product'; | ||
83 | + break; | ||
84 | + default: // 其它(识别为品牌) | ||
85 | + $module = 'Brand'; | ||
86 | + break; | ||
87 | + } | ||
88 | + } | ||
89 | + $dispatcher->getRequest()->module = $module; | ||
90 | + | ||
91 | + /* 根据对应模块的配置,添加相应的路由规则 */ | ||
92 | + $iniFile = APPLICATION_PATH . '/configs/routes.' . strtolower($module) . 'ini'; | ||
93 | + if (file_exists($iniFile)) { | ||
94 | + $config = new Config\Ini($iniFile); | ||
68 | if (isset($config->routes)) { | 95 | if (isset($config->routes)) { |
69 | $dispatcher->getRouter()->addConfig($config->routes); | 96 | $dispatcher->getRouter()->addConfig($config->routes); |
70 | } | 97 | } |
71 | } | 98 | } |
72 | 99 | ||
100 | + } | ||
101 | + | ||
73 | /** | 102 | /** |
74 | * 初始化Layout | 103 | * 初始化Layout |
75 | * @param Yaf_Dispatcher $dispatcher | 104 | * @param Yaf_Dispatcher $dispatcher |
-
Please register or login to post a comment