15807105408 2016-02-03 16:33:54 3867次浏览 0条评论 0 0 0

1.在入口文件配置
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(DIR . '/../../vendor/autoload.php');
require(DIR . '/../../vendor/yiisoft/yii2/Yii.php');
require(DIR . '/../../vendor/thirdparty/dump.php');
require(DIR . '/../../common/config/bootstrap.php');
require(DIR . '/../config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(

require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../../common/config/db.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')

);

$application = new yii\web\Application($config);
//入口文件配置
$application->language=isset(\Yii::$app->session['language'])?\Yii::$app->session['language']:'zh-CN';
$application->run();
2.config 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')

);

return [

'id' => 'app-manageend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'defaultRoute'=>'index/index',
'controllerNamespace' => 'manageend\controllers',

//配置环境

'on beforeRequest' => function ($event) {
    $l_saved = null;
    if (true){
        # use cookie to store language
        $l_saved = Yii::$app->request->cookies->get('locale');
    }else{
        # use session to store language
        $l_saved = Yii::$app->session['locale'];
    }
    $l = ($l_saved)?$l_saved:'zh-CN';

    Yii::$app->sourceLanguage = 'zh';
    Yii::$app->language = $l;
    return; 
},  

//配置环境

'components' => [
    'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
    ],
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
        ],
    ],
    'errorHandler' => [
        'errorAction' => 'site/error',
    ],
],
'params' => $params,

];

    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册