2017-04-12 99 views
0

我想知道如何Yii框架發送取決於在URL中傳遞的子域名的請求權控制器:Yii框架和DINAMIC子域

www.mysystem.com - >這個請求被默認處理我係統中特定模塊的控制器。

但是當用戶來訪問他的商店時,他將使用URL:storename.mysystem.com。 (有很多不同的商店名稱)

我想知道哪裏在Yii我可以找到配置來設置哪個模塊/控制器將處理此請求。

謝謝。

回答

0

這裏是我的Yii2

配置

main.php

<?php 
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'), 
    require(__DIR__ . '/../../common/config/params-local.php'), 
    require(__DIR__ . '/params.php'), 
    require(__DIR__ . '/params-local.php') 
); 

$host = (!empty($_SERVER['HTTP_HOST']))?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME']; 
$segments = explode('.',$host); 
defined('SUBDOMAIN') or define('SUBDOMAIN', strtolower($segments[0])); 

return [ 
    'id' => 'app-backend', 
    'basePath' => dirname(__DIR__), 
    'controllerNamespace' => 'backend\controllers', 
    'bootstrap' => ['log'], 
    'modules' => [ 
     SUBDOMAIN => [ 
      'class' => 'backend\modules\\'.SUBDOMAIN.'\\'.ucfirst(SUBDOMAIN), 
     ], 
    ], 
    'components' => [ 
     'request' => [ 
      'csrfParam' => '_csrf-backend', 
     ], 
     'user' => [ 
      'identityClass' => 'common\models\User', 
      'enableAutoLogin' => true, 
      'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], 
     ], 
     'session' => [ 
      // this is the name of the session cookie used for login on the backend 
      'name' => 'advanced-backend', 
     ], 
     'log' => [ 
      'traceLevel' => YII_DEBUG ? 3 : 0, 
      'targets' => [ 
       [ 
        'class' => 'yii\log\FileTarget', 
        'levels' => ['error', 'warning'], 
       ], 
      ], 
     ], 
     'errorHandler' => [ 
      'errorAction' => 'site/error', 
     ], 
     'db' => [ 
      'tablePrefix' => SUBDOMAIN.'_', 
     ], 
     'urlManager'=>[ 
      'rules' => [ 
       '<controller:[\w-]+>/<id:\d+>' => ''.SUBDOMAIN.'/<controller>/view', 
       '<controller:[\w-]+/<action:[\w-]+>' => ''.SUBDOMAIN.'/<controller>/<action>', 
       '<controller:[\w-]+>/<action:[\w-]+>/<id:\d+>' => ''.SUBDOMAIN.'/<controller>/<action>', 
      ], 
     ], 

    ], 
    'params' => $params, 
];