|
EnvironmentClass
Describes workings and usage of the Yii Environment-class.
Environment-classOriginal sources: http://www.yiiframework.com/doc/cookbook/73/ Simple class used to set configuration and debugging depending on environment. Using this you can predefine configurations for use in different environments, like development, testing, staging and production. The main config (main.php) is extended to include the Yii paths and debug flags. There are mode_ENVIRONMENT.php files for overriding and extending main.php for specific environments. Additionally, you can overrride the resulting config by using a local.php config, to make changes that will only apply to your specific installation. This class was designed to have minimal impact on the default Yii generated files. Minimal changes to the index/bootstrap and existing config files are needed. You can optionally override the environment by creating a mode.php in the config directory. The Environment is determined with PHP's getenv(), which searches $_SERVER and $_ENV. There are multiple ways to set the environment depending on your preference. Setting the environment variable is trivial on both Windows and Linux, instructions included. If you want to customize this class or its config and modes, extend it! (see ExampleEnvironment.php) Installation
Setting environmentHere are some examples for setting your environment to DEVELOPMENT.
After setting environment/apache vars, you probably need to relog and restart the server. Problems?
Index.php usage example:See yii-environment/example-index/ or use the following code block: <?php
// set environment
require_once(dirname(__FILE__) . '/protected/extensions/yii-environment/Environment.php');
$env = new Environment();
//$env = new Environment('PRODUCTION'); //override mode
// set debug and trace level
defined('YII_DEBUG') or define('YII_DEBUG', $env->yiiDebug);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', $env->yiiTraceLevel);
// run Yii app
//$env->showDebug(); // show produced environment configuration
require_once($env->yiiPath);
$env->runYiiStatics(); // like Yii::setPathOfAlias()
Yii::createWebApplication($env->configWeb)->run();Structure of config directoryYour protected/config/ directory will look like this:
Modify your config/main.phpSee yii-environment/example-config/ or use the following code block: Optional: in configConsole you can copy settings from configWeb by using value key inherit (see examples folder). <?php
return array(
// Set yiiPath (relative to Environment.php)
'yiiPath' => dirname(__FILE__) . '/../../../yii/framework/yii.php',
'yiicPath' => dirname(__FILE__) . '/../../../yii/framework/yiic.php',
'yiitPath' => dirname(__FILE__) . '/../../../yii/framework/yiit.php',
// Set YII_DEBUG and YII_TRACE_LEVEL flags
'yiiDebug' => true,
'yiiTraceLevel' => 0,
// Static function Yii::setPathOfAlias()
'yiiSetPathOfAlias' => array(
// uncomment the following to define a path alias
//'local' => 'path/to/local-folder'
),
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
'configWeb' => array(
(...)
),
// This is the Console application configuration. Any writable
// CConsoleApplication properties can be configured here.
// Leave array empty if not used.
// Use value 'inherit' to copy from generated configWeb.
'configConsole' => array(
(...)
),
);Create mode-specific config filesCreate config/mode_<mode>.php files for the different modes These will override or merge attributes that exist in the main config. Optional: also create a config/local.php file for local overrides <?php
return array(
// Set yiiPath (relative to Environment.php)
//'yiiPath' => dirname(__FILE__) . '/../../../yii/framework/yii.php',
//'yiicPath' => dirname(__FILE__) . '/../../../yii/framework/yiic.php',
//'yiitPath' => dirname(__FILE__) . '/../../../yii/framework/yiit.php',
// Set YII_DEBUG and YII_TRACE_LEVEL flags
'yiiDebug' => true,
'yiiTraceLevel' => 0,
// Static function Yii::setPathOfAlias()
'yiiSetPathOfAlias' => array(
// uncomment the following to define a path alias
//'local' => 'path/to/local-folder'
),
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
'configWeb' => array(
(...)
),
// This is the Console application configuration. Any writable
// CConsoleApplication properties can be configured here.
// Leave array empty if not used
// Use value 'inherit' to copy from generated configWeb
'configConsole' => array(
(...)
),
);
|
i got some error while running this :"Environment mode cannot be determined, see class for instructions.' in C:\wamp\www\mytestsite\protected\extensions\yii-environment\Environment.php on line 284:
portalfever.com
Try the steps mensioned under "Setting environment" on this page. Reboot your server/machine after completing the steps.