[置頂] yii 1.0配置文件解析
來源:程序員人生 發布時間:2014-11-12 08:56:59 閱讀次數:3732次
yii中配置文件主要是1個入口文件,然后
main.php
<?php
// 取消下行的注釋,來定義1個路徑別名
// http://www.vxbq.cn/yii/::setPathOfAlias('local','path/to/local-folder');
// 這是 Web 利用配置的主體部份。任何可寫的
// CWebApplication 屬性可以在這里配置。
$config = array(
// protected 目錄的基礎路徑
// 使用 http://www.vxbq.cn/yii/::app()->basePath 來訪問
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
// 利用的名字
// 使用 http://www.vxbq.cn/yii/::app()->name 來訪問
'name' => 'My website',
//路徑別名
// 可以是利用內部的路徑,也能夠是外部資源
'aliases' => array(
'myExternalFramework' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'myexternalframework'
),
//保護程序時,這模樣所有的要求轉發到1個地方
'catchAllRequest' => array('site/all'),
//如何在利用程序處理要求之前履行1段操作?固然這個function方法要存在index.php
'onBeginRequest' => 'function',
//controller path
'controllerMap' => array('myController' => 'myExternalFramework.controllers.MyController'),
// 默許的 controller
'defaultController' => 'site',
// 用戶語言(for Locale)
'language' => 'es',
//信息和視圖的語言
'sourceLanguage' => 'es',
'timeZone' => 'Asia/Shanghai',
'theme' => 'default',
// 使用的字符集
'charset' => 'utf⑻',
// 預載入的利用組件
'preload' => array('log'),
// 自動載入的類
'import' => array(
'application.models.*',
'application.components.*',
),
// 可使用 http://www.vxbq.cn/yii/::app()->params['paramName'] 訪問的利用級別的參數
'params' => require(dirname(__FILE__) . '/params.php'),
// 在 params.php 中你需要返回這個數組:http://www.vxbq.cn/yii/::app()->setParams設置的只能用http://www.vxbq.cn/yii/::app()->params['xxx']這類數組的方式訪問
// return array('adminEmail'=>'info@example.com');
// 利用組件的配置
'components' => array(
// assets, 參考www.yiiframework.com/doc/api/CAssetManager
'assetManager' => array(
// 改變磁盤上的路徑
'basePath' => dirname(__FILE__) . '/../../assets/',
// 改變url
'baseUrl' => '/web/assets/'
),
'request' => array(
'enableCsrfValidation' => true, //如果避免post跨站攻擊
'enableCookieValidation' => true, //避免Cookie攻擊
),
// 緩存
'cache' => array(
'class' => 'A cache class, like: system.caching.CApcCache',
),
'session' => array( // memcache session cache
'class' => 'CCacheHttpSession',
'autoStart' => 1,
'sessionName' => 'frontend',
'cookieParams' => array('lifetime' => '3600', 'path' => '/', 'domain' => '.test.com', 'httponly' => '1'),
'cookieMode' => 'only',
),
// 你可使用 scriptMap 來配置腳本來自哪里。
// 對1個生產環境的配置,以下
'clientScript' => array(
'scriptMap' => array(
'register.js' => 'site.min.js',
'login.js' => 'site.min.js',
),
),
// 對1個開發環境,可以這樣做
'clientScript' => array(
'scriptMap' => array(
'register.js' => 'register.js',
'login.js' => 'login.js',
),
),
),
);
$database = require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'db.php');
if (!empty($database)) {
$config['components'] = CMap::mergeArray($config['components'],$database);
// http://www.vxbq.cn/yii/::app()->setComponents($database);
}
return $config;
db.php
<?php
return array(
'db' => array(
'connectionString' => 'mysql:host=192.168.1.240;dbname=tttt',
'emulatePrepare' => true,
'username' => 'root',
'password' => '****',
'charset' => 'utf8',
),
'card' => array(
'class' => 'CDbConnection',//
'connectionString' => 'mysql:host=192.168.1.240;dbname=card',
'emulatePrepare' => true,
'username' => 'root',
'password' => '**',
'charset' => 'utf8',
),
);
params.php
<?php
return array(
'adminEmail'=>'info@example.com',
'pagesize'=>'100',
'pager'=>array(
'class'=>'PagerWidget',
'maxButtonCount'=>8,
'firstPageLabel'=>'首頁',
'lastPageLabel'=>'末頁',
'nextPageLabel'=>'下1頁',
'prevPageLabel'=>'上1頁',
'header'=>'',
'cssFile'=>false,
),
);
index.php
配置環境常量,不同環境調用不同配置文件和調試級別。
/**
* 利用程序環境,可選:development,production,
*/
defined('APP_ENV') or define('APP_ENV','development');
// change the following paths if necessary
if (APP_ENV == 'production') {
error_reporting(0);
$yii=dirname(__FILE__).'/framework/yiilite.php';
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',1);
} else {
$yii=dirname(__FILE__).'/framework/yii.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);
}
$config=dirname(__FILE__).'/protected/config/'.APP_ENV.'.php';
require('path/to/globals.php'); //見附件
require_once($yii);
http://www.vxbq.cn/yii/::createWebApplication($config)->run();
development.php
開啟weblog,profile,http://www.vxbq.cn/db/性能顯示,http://www.vxbq.cn/db/查詢參數記錄,GII
production.php
開啟http://www.vxbq.cn/db/結構緩存,關閉毛病顯示
<?php
return CMap::mergeArray(
require(dirname(__FILE__).'/main.php'),
array(
'components'=>array(
// uncomment the following to use a MySQL database
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
)
),
),
),
)
);
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈