Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
<?php
// Config base dir
$base = dirname(__FILE__).DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.
'config'.DIRECTORY_SEPARATOR;
// Get the domain
$domain = $_SERVER['SERVER_NAME'];
if (strpos($domain, 'www.') !== false) {
$domain = str_replace('www.', '', $domain);
}
if (!file_exists($base.'sites'.DIRECTORY_SEPARATOR.$domain.'.php')) {
$domain = 'dev.example.com';
}
$main = include($base.'main.php');
$domain_config = include($base.DIRECTORY_SEPARATOR.'sites'.DIRECTORY_SEPARATOR.$domain.'.php');
// Load the Yii framework
$yii=dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'yii'
.DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR
.(defined('YII_DEBUG') ? 'yii.php' : 'yiilite.php');
require_once($yii);
// Merge configs
$config = CMap::mergeArray($main, $domain_config);
// Init the application
/** @var $app CWebApplication */
$app = Yii::createWebApplication($config);
unset($domain, $base, $yii, $config, $main, $domain_config);
Yii::import("ext.yiiext.components.zendAutoloader.EZendAutoloader", true);
// you are able to load custom code that is using Zend class naming convention
// with different prefix
EZendAutoloader::$prefixes = array('Zend', 'Custom');
Yii::registerAutoloader(array("EZendAutoloader", "loadClass"));
$app->run();
<?php
return array(
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'defaultController' => 'site',
'components' => array(
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'urlSuffix'=> '.html',
'rules' => array(
'<lang:\w{2}>/<controller:\w+>/<id:\d+>' => '<controller>/view',
'<lang:\w{2}>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<lang:\w{2}>/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<lang:\w{2}>/<controller:\w+>' => '<controller>/index',
),
),
'db' => array(
'class' => 'system.db.CDbConnection',
'charset' => 'utf8',
'schemaCachingDuration'=>3600,
'emulatePrepare' => true,
),
),
'params' => array(
'mail' => array(
'smtp_from' => 'example@example.com',
'pass' => '12345',
'ip' => '192.168.0.1',
'port' => '25',
),
),
);
<?php
return array(
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=mysql_host;dbname=project_db',
'username' => 'production',
'password' => 'production password',
),
),
);
<?php
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
return array(
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=project_db',
'username' => 'devuser',
'password' => 'dev password',
'enableProfiling' => true,
'enableParamLogging' => true,
'schemaCachingDuration' => 0,
),
),
'params' => array(
'mail' => array(
'smtp_from' => 'test@example.com',
'pass' => 'localtest',
'ip' => 'localhost',
'port' => '25',
),
),
);
$webRoot = dirname(__FILE__);
$author = null;
$authorFile = $webRoot . '/.author';
if (is_file($authorFile)) {
$author = trim(file_get_contents($authorFile));
}
if (!empty($author)) {
$config = $webRoot . '/protected/config/' . $author . '.php';
if (!file_exists($config)) {
$config = $webRoot . '/protected/config/main.php';
}
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
} else {
$config = $webRoot . '/protected/config/production.php';
}
<?php
return CMap::mergeArray(
require(dirname(__FILE__) . '/main.php'),
array(
'components'=>array(
'db' => array(
...
),
),
)
);
Различные конфиги для режима production и режима отладки. Два в одном