- Preparación para 1ª maqueta real
git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_IntranetNueva/trunk@26 77cfc57b-8ef4-1849-9df6-4a38aa5da120
This commit is contained in:
parent
93dfffa646
commit
80240e9711
@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
// set environment
|
||||
require_once(dirname(__FILE__) . '/protected/config/Environment.php');
|
||||
//$env = new Environment();
|
||||
$env = new Environment('DEVELOPMENT'); //override
|
||||
|
||||
// set debug and trace level
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', $env->getDebug());
|
||||
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', $env->getTraceLevel());
|
||||
|
||||
// run Yii app
|
||||
require_once($env->getYiiPath());
|
||||
Yii::createWebApplication($env->getConfig())->run();
|
||||
|
||||
// change the following paths if necessary
|
||||
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
|
||||
$config=dirname(__FILE__).'/protected/config/main.php';
|
||||
|
||||
// remove the following lines when in production mode
|
||||
defined('YII_DEBUG') or define('YII_DEBUG',true);
|
||||
// specify how many levels of call stack should be shown in each log message
|
||||
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
|
||||
|
||||
require_once($yii);
|
||||
Yii::createWebApplication($config)->run();
|
||||
?>
|
||||
209
www/protected/config/Environment.php
Normal file
209
www/protected/config/Environment.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simple class used to set configuration and debugging depending on environment.
|
||||
* This allows for a custom Yii path, debugging vars, and config array.
|
||||
*
|
||||
* Environment is determined by $_SERVER[YII_ENVIRONMENT], created
|
||||
* by Apache's SetEnv directive
|
||||
* This can be done in the httpd.conf or in a .htaccess file for ease of use.
|
||||
* See: http://httpd.apache.org/docs/1.3/mod/mod_env.html#setenv
|
||||
*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Index.php usage example:
|
||||
*
|
||||
* // set environment
|
||||
* require_once(dirname(__FILE__) . '/protected/config/Environment.php');
|
||||
* $env = new Environment();
|
||||
* //$env = new Environment('PRODUCTION'); //override
|
||||
*
|
||||
* // set debug and trace level
|
||||
* defined('YII_DEBUG') or define('YII_DEBUG', $env->getDebug());
|
||||
* defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', $env->getTraceLevel());
|
||||
*
|
||||
* // run Yii app
|
||||
* require_once($env->getYiiPath());
|
||||
* Yii::createWebApplication($env->getConfig())->run();
|
||||
*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Modify your config/main.php like this:
|
||||
*
|
||||
* // Set yiiPath (add extra ../../)
|
||||
* $yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
*
|
||||
* // Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
* $debug = true;
|
||||
* $traceLevel = 0;
|
||||
*
|
||||
* // Set config array
|
||||
* $config = array(
|
||||
*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Create config/mode_<mode>.php files for the different modes
|
||||
* These will override or merge attributes
|
||||
*
|
||||
* // Set yiiPath (add extra ../../)
|
||||
* //$yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
*
|
||||
* // Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
* $debug = false;
|
||||
* $traceLevel = 0;
|
||||
*
|
||||
* // Set specific config
|
||||
* $configSpecific = array(
|
||||
*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Usage example for checking environment in code:
|
||||
*
|
||||
* // Compare if the current environment is lower than production
|
||||
* $currentEnvironment = Yii::app()->getParams()->environment; //gets integer
|
||||
* if ($currentEnvironment < Environment::PRODUCTION) {
|
||||
* //do this
|
||||
* } else {
|
||||
* //do that
|
||||
* }
|
||||
*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Original sources: http://www.yiiframework.com/doc/cookbook/73/
|
||||
*
|
||||
* @name Environment
|
||||
* @author Marco van 't Wout | Tremani
|
||||
* @version 1.0
|
||||
* @property string mode the current environment mode
|
||||
* @property boolean debug the debug flag
|
||||
* @property integer traceLevel the trace level
|
||||
* @property string yiiPath path to the Yii framework
|
||||
* @property string config the merged config array
|
||||
*
|
||||
*/
|
||||
class Environment
|
||||
{
|
||||
|
||||
// $_SERVER[SERVER_VAR]
|
||||
const SERVER_VAR = 'YII_ENVIRONMENT';
|
||||
const MAIN_CONFIG = 'main.php';
|
||||
|
||||
// Modes
|
||||
const DEVELOPMENT = 100;
|
||||
const TEST = 200;
|
||||
const STAGE = 300;
|
||||
const PRODUCTION = 400;
|
||||
|
||||
// Current mode
|
||||
private $_mode;
|
||||
|
||||
// Environment properties
|
||||
private $_debug;
|
||||
private $_traceLevel;
|
||||
private $_yiiPath;
|
||||
private $_config;
|
||||
|
||||
/**
|
||||
* Initilizes the Environment class with the given mode
|
||||
* @param constant $mode
|
||||
*/
|
||||
function __construct($mode = null)
|
||||
{
|
||||
$this->_mode = $this->getMode($mode);
|
||||
$this->setEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current environment mode depending on environment variable
|
||||
* @param <type> $mode
|
||||
* @return <type>
|
||||
*/
|
||||
private function getMode($mode = null)
|
||||
{
|
||||
// If not overriden
|
||||
if (!isset($mode))
|
||||
{
|
||||
// Return mode based on Apache server var
|
||||
if (isset($_SERVER[self::SERVER_VAR]))
|
||||
$mode = $_SERVER[self::SERVER_VAR];
|
||||
else
|
||||
throw new Exception('SetEnv YII_ENVIRONMENT <mode> not defined in Apache config.');
|
||||
}
|
||||
|
||||
// Check if mode is valid
|
||||
if (!defined('self::' . $mode))
|
||||
throw new Exception('Invalid Environment mode');
|
||||
|
||||
return $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the environment and configuration for the chosen mode
|
||||
* @param constant $mode
|
||||
*/
|
||||
private function setEnvironment()
|
||||
{
|
||||
// Load main config
|
||||
$configMainFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::MAIN_CONFIG;
|
||||
if (!file_exists($configMainFile))
|
||||
throw new Exception('Cannot find config file "' . $configMainFile . '".');
|
||||
require($configMainFile);
|
||||
|
||||
// Load specific config
|
||||
$configFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mode_' . strtolower($this->_mode) . '.php';
|
||||
if (!file_exists($configFile))
|
||||
throw new Exception('Cannot find config file "' . $configFile . '".');
|
||||
require($configFile);
|
||||
|
||||
// Merge config arrays into one
|
||||
//$this->_config = array_merge_recursive($config, $configSpecific);
|
||||
require_once(dirname($yiiPath). DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . 'CComponent.php');
|
||||
require_once(dirname($yiiPath). DIRECTORY_SEPARATOR . 'collections' . DIRECTORY_SEPARATOR . 'CMap.php');
|
||||
$this->_config = CMap::mergeArray($config, $configSpecific);
|
||||
|
||||
// Set other environment vars
|
||||
$this->_yiiPath = $yiiPath;
|
||||
$this->_debug = $debug;
|
||||
$this->_traceLevel = $traceLevel;
|
||||
$this->_config['params']['environment'] = constant('self::' . $this->_mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the Yii framework
|
||||
* @return string
|
||||
*/
|
||||
public function getYiiPath()
|
||||
{
|
||||
return $this->_yiiPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the debug mode for YII_DEBUG
|
||||
* @return Bool
|
||||
*/
|
||||
public function getDebug()
|
||||
{
|
||||
return $this->_debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the trace level for YII_TRACE_LEVEL
|
||||
* @return int
|
||||
*/
|
||||
public function getTraceLevel()
|
||||
{
|
||||
return $this->_traceLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration array
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
// uncomment the following to define a path alias
|
||||
// Yii::setPathOfAlias('local','path/to/local-folder');
|
||||
// Set yiiPath (add extra ../../)
|
||||
$yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
|
||||
// Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
$debug = true;
|
||||
$traceLevel = 0;
|
||||
|
||||
// This is the main Web application configuration. Any writable
|
||||
// CWebApplication properties can be configured here.
|
||||
return array(
|
||||
$config = array(
|
||||
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
|
||||
'name'=>'My Web Application',
|
||||
'name'=>'Intranet',
|
||||
'sourceLanguage' =>'en_US',
|
||||
'language' =>'es',
|
||||
|
||||
@ -22,15 +24,6 @@ return array(
|
||||
),
|
||||
|
||||
'modules'=>array(
|
||||
// uncomment the following to enable the Gii tool
|
||||
|
||||
'gii'=>array(
|
||||
'class'=>'system.gii.GiiModule',
|
||||
'password'=>'password',
|
||||
// If removed, Gii defaults to localhost only. Edit carefully to taste.
|
||||
'ipFilters'=>array('127.0.0.1','::1'),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
// application components
|
||||
@ -48,32 +41,10 @@ return array(
|
||||
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
|
||||
),
|
||||
),
|
||||
'db'=>array(
|
||||
'connectionString' => 'mysql:host=localhost;dbname=intranet_dev',
|
||||
'emulatePrepare' => true,
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'charset' => 'utf8',
|
||||
),
|
||||
'errorHandler'=>array(
|
||||
// use 'site/error' action to display errors
|
||||
'errorAction'=>'site/error',
|
||||
),
|
||||
'log'=>array(
|
||||
'class'=>'CLogRouter',
|
||||
'routes'=>array(
|
||||
array(
|
||||
'class'=>'CFileLogRoute',
|
||||
'levels'=>'error, warning',
|
||||
),
|
||||
// uncomment the following to show log messages on web pages
|
||||
/*
|
||||
array(
|
||||
'class'=>'CWebLogRoute',
|
||||
),
|
||||
*/
|
||||
),
|
||||
),
|
||||
'widgetFactory'=>array(
|
||||
'widgets'=>array(
|
||||
'CLinkPager'=>array(
|
||||
@ -87,7 +58,7 @@ return array(
|
||||
// using Yii::app()->params['paramName']
|
||||
'params'=>array(
|
||||
// PageSize extension
|
||||
'defaultPageSize' => 10,
|
||||
'defaultPageSize' => 50,
|
||||
'pageSizeOptions' => array(10=>10,20=>20,50=>50,100=>100),
|
||||
),
|
||||
);
|
||||
67
www/protected/config/mode_development.php
Normal file
67
www/protected/config/mode_development.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Development configuration
|
||||
* Usage:
|
||||
* - Local website
|
||||
* - Local DB
|
||||
* - Show all details on each error.
|
||||
* - Gii module enabled
|
||||
*/
|
||||
|
||||
|
||||
// Set yiiPath (add extra ../../)
|
||||
//$yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
|
||||
// Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
$debug = true;
|
||||
$traceLevel = 3;
|
||||
|
||||
|
||||
// Set specific config
|
||||
$configSpecific = array(
|
||||
|
||||
// Modules
|
||||
'modules' => array(
|
||||
'gii' => array(
|
||||
'class' => 'system.gii.GiiModule',
|
||||
'password' => 'password',
|
||||
),
|
||||
),
|
||||
|
||||
// Application components
|
||||
'components' => array(
|
||||
|
||||
// Database
|
||||
'db' => array(
|
||||
'connectionString' => 'mysql:host=localhost;dbname=intranet_dev',
|
||||
'emulatePrepare' => true,
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'charset' => 'utf8',
|
||||
),
|
||||
|
||||
// Application Log
|
||||
'log' => array(
|
||||
'class' => 'CLogRouter',
|
||||
'routes' => array(
|
||||
// Save log messages on file
|
||||
array(
|
||||
'class' => 'CFileLogRoute',
|
||||
'levels' => 'error, warning, trace, info',
|
||||
),
|
||||
// Show log messages on web pages
|
||||
array(
|
||||
'class' => 'CWebLogRoute',
|
||||
//'categories' => 'system.db.CDbCommand',
|
||||
'levels' => 'error, warning, trace, info',
|
||||
//'showInFireBug' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
?>
|
||||
55
www/protected/config/mode_production.php
Normal file
55
www/protected/config/mode_production.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Production configuration
|
||||
* Usage:
|
||||
* - online website
|
||||
* - Production DB
|
||||
* - Standard production error pages (404,500, etc.)
|
||||
*/
|
||||
|
||||
|
||||
// Set yiiPath (add extra ../../)
|
||||
//$yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
|
||||
// Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
$debug = false;
|
||||
$traceLevel = 0;
|
||||
|
||||
|
||||
// Set specific config
|
||||
$configSpecific = array(
|
||||
|
||||
// Application components
|
||||
'components' => array(
|
||||
|
||||
// Database
|
||||
'db' => array(
|
||||
'connectionString' => 'mysql:host=PRODUCTION_HOST;dbname=PRODUCTION_DBNAME',
|
||||
'username' => 'USERNAME',
|
||||
'password' => 'PASSWORD',
|
||||
),
|
||||
|
||||
// Application Log
|
||||
'log' => array(
|
||||
'class' => 'CLogRouter',
|
||||
'routes' => array(
|
||||
// Save log messages on file
|
||||
array(
|
||||
'class' => 'CFileLogRoute',
|
||||
'levels' => 'error, warning, trace, info',
|
||||
),
|
||||
// Send errors via email to the system admin
|
||||
array(
|
||||
'class' => 'CEmailLogRoute',
|
||||
'levels' => 'error, warning',
|
||||
'emails' => 'marco@example.com',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
?>
|
||||
49
www/protected/config/mode_stage.php
Normal file
49
www/protected/config/mode_stage.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Stage configuration
|
||||
* Usage:
|
||||
* - Online website
|
||||
* - Production DB
|
||||
* - All details on error
|
||||
*/
|
||||
|
||||
|
||||
// Set yiiPath (add extra ../../)
|
||||
//$yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
|
||||
// Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
$debug = true;
|
||||
$traceLevel = 0;
|
||||
|
||||
|
||||
// Set specific config
|
||||
$configSpecific = array(
|
||||
|
||||
// Application components
|
||||
'components' => array(
|
||||
|
||||
// Database
|
||||
'db' => array(
|
||||
'connectionString' => 'mysql:host=STAGING_HOST;dbname=STAGING_DBNAME',
|
||||
'username' => 'USERNAME',
|
||||
'password' => 'PASSWORD',
|
||||
),
|
||||
|
||||
// Application Log
|
||||
'log' => array(
|
||||
'class' => 'CLogRouter',
|
||||
'routes' => array(
|
||||
// Save log messages on file
|
||||
array(
|
||||
'class' => 'CFileLogRoute',
|
||||
'levels' => 'error, warning, trace, info',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
?>
|
||||
63
www/protected/config/mode_test.php
Normal file
63
www/protected/config/mode_test.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test configuration
|
||||
* Usage:
|
||||
* - Local website
|
||||
* - Local DB
|
||||
* - Standard production error pages (404, 500, etc.)
|
||||
*/
|
||||
|
||||
|
||||
// Set yiiPath (add extra ../../)
|
||||
//$yiiPath = dirname(__FILE__) . '/../../../yii/framework/yii.php';
|
||||
|
||||
// Set YII_DEBUG and YII_TRACE_LEVEL flags
|
||||
$debug = false;
|
||||
$traceLevel = 0;
|
||||
|
||||
|
||||
// Set specific config
|
||||
$configSpecific = array(
|
||||
|
||||
// Application components
|
||||
'components' => array(
|
||||
|
||||
// Database
|
||||
'db'=>array(
|
||||
'connectionString' => 'mysql:host=localhost;dbname=intranet_test',
|
||||
'emulatePrepare' => true,
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'charset' => 'utf8',
|
||||
),
|
||||
|
||||
// Fixture Manager for testing
|
||||
'fixture' => array(
|
||||
'class' => 'system.test.CDbFixtureManager',
|
||||
),
|
||||
|
||||
// Application Log
|
||||
'log' => array(
|
||||
'class' => 'CLogRouter',
|
||||
'routes' => array(
|
||||
// Save log messages on file
|
||||
array(
|
||||
'class' => 'CFileLogRoute',
|
||||
'levels' => 'error, warning, trace, info',
|
||||
),
|
||||
// Show log messages on web pages
|
||||
array(
|
||||
'class' => 'CWebLogRoute',
|
||||
//'categories' => 'system.db.CDbCommand',
|
||||
'levels' => 'error, warning',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
|
||||
?>
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
return CMap::mergeArray(
|
||||
require(dirname(__FILE__).'/main.php'),
|
||||
array(
|
||||
'components'=>array(
|
||||
'fixture'=>array(
|
||||
'class'=>'system.test.CDbFixtureManager',
|
||||
),
|
||||
'db'=>array(
|
||||
'connectionString' => 'mysql:host=localhost;dbname=intranet_test',
|
||||
'emulatePrepare' => true,
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'charset' => 'utf8',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
@ -1,10 +1,14 @@
|
||||
<?php
|
||||
|
||||
// change the following paths if necessary
|
||||
|
||||
$yiit=dirname(__FILE__).'/../../../yii/framework/yiit.php';
|
||||
$config=dirname(__FILE__).'/../config/test.php';
|
||||
|
||||
// set environment
|
||||
require_once(dirname(__FILE__) . '/../config/Environment.php');
|
||||
$env = new Environment('TEST'); //override
|
||||
$config = $env->getConfig();
|
||||
|
||||
// run Yii app
|
||||
require_once($yiit);
|
||||
require_once(dirname(__FILE__).'/WebTestCase.php');
|
||||
|
||||
Yii::createWebApplication($config);
|
||||
Yii::createWebApplication($config);
|
||||
Loading…
Reference in New Issue
Block a user