crisu83/yii-configbuilder

用于构建 Yii PHP 框架应用配置的辅助工具。

安装: 626

依赖者: 1

建议者: 0

安全: 0

星标: 12

关注者: 3

分支: 8

类型:yii-extension

dev-master 2013-03-27 21:39 UTC

This package is auto-updated.

Last update: 2024-08-29 03:15:50 UTC


README

用于构建 Yii PHP 框架应用配置的辅助工具。

基本配置

用法

要使用配置构建器,只需在您的入口脚本中加载它

<?php
$yii = __DIR__ . '/path/to/yii.php';
$builder = __DIR__ . '/path/to/ConfigBuilder.php';

require_once($yii);
require_once($builder);

$config = ConfigBuilder::build(array(
    __DIR__ . '/protected/config/common.php',
    __DIR__ . '/protected/config/web.php',
    __DIR__ . '/protected/config/dev.php',
    __DIR__ . '/protected/config/local.php',
));

Yii::createWebApplication($config)->run();

index.php

特定环境配置

如果您需要在您的应用程序中不同环境,您可以使用 buildForEnv 方法与 EnvCommand 一起轻松设置特定环境的配置。

配置

将 env 命令添加到您的控制台配置文件(通常是 protected/config/console.php

// console application configuration
return array(
    .....
    'commandMap' => array(
        'env' => array(
            'class' => 'path.alias.to.EnvCommand',
            // optional configurations
            'runtimePath' => 'application.runtime', // the path to the application runtime folder
            'envPaths' => array('application.config.environments'), // the paths to application environment configs
        ),
    ),
);

console.php

用法

更新您的入口脚本(通常是 index.php)以使用 buildForEnv 方法。

<?php
$config = ConfigBuilder::buildForEnv(array(
    __DIR__ . '/protected/config/common.php',
    __DIR__ . '/protected/config/web.php',
    __DIR__ . '/protected/config/environments/{environment}.php',
    __DIR__ . '/protected/config/local.php',
), __DIR__ . '/protected/runtime/environment');

index.php

现在您可以使用 env 命令来设置活动环境(替换 {environment} 为环境的名称)

yiic env {environment}

注意:您不需要创建环境配置文件,如果它们不存在,命令将提示您创建它们。