首页 > 活着 > YII 配置文件

YII 配置文件

用YIIFramework的库开发

Java代码
1…..
2.Yii::createWebApplication($config); //没有run
….
Yii::createWebApplication($config); //没有runYii::import(class1,true),在将class1类文件路径存储时,同时include该文件

注意:你也可以将配置文件分为多个文件, // 例如: db.php, params.php等等

main.php

Java代码
1. 2.// 取消下行的注释,来定义一个路径别名
3.// Yii::setPathOfAlias('local','path/to/local-folder');
4.
5.// 这是 Web 应用配置的主体部分。任何可写的
6.// CWebApplication 属性可以在这里配置。
7.$config = array(
8. // protected 目录的基础路径
9. // 使用 Yii::app()->basePath 来访问
10. ‘basePath’ => dirname(__FILE__) . DIRECTORY_SEPARATOR . ‘..’,
11.
12. // 应用的名字
13. // 使用 Yii::app()->name 来访问
14. ‘name’ => ‘My website’,
15.
16. //路径别名
17. // 可以是应用内部的路径,也可以是外部资源
18. ‘aliases’ => array(
19. ‘myExternalFramework’ => dirname(__FILE__) . DIRECTORY_SEPARATOR . ‘..’ . DIRECTORY_SEPARATOR . ‘..’ . DIRECTORY_SEPARATOR . ‘myexternalframework’
20. ),
21. //维护程序时,这样子所有的请求转发到一个地方
22. ‘catchAllRequest’ => array(‘site/all’),
23.
24. //如何在应用程序处理请求之前执行一段操作?当然这个function方法要存在index.php
25. ‘onBeginRequest’ => ‘function’,
26.
27. //controller path
28. ‘controllerMap’ => array(‘myController’ => ‘myExternalFramework.controllers.MyController’),
29.
30. // 默认的 controller
31. ‘defaultController’ => ‘site’,
32.
33. // 用户语言(for Locale)
34. ‘language’ => ‘es’,
35.
36. //信息和视图的语言
37. ‘sourceLanguage’ => ‘es’,
38. ‘timeZone’ => ‘Asia/Shanghai’,
39. ‘theme’ => ‘default’,
40. // 使用的字符集
41. ‘charset’ => ‘utf-8′,
42.
43. // 预载入的应用组件
44. ‘preload’ => array(‘log’),
45.
46. // 自动载入的类
47. ‘import’ => array(
48. ‘application.models.*’,
49. ‘application.components.*’,
50. ),
51.
52. // 可以使用 Yii::app()->params[‘paramName’] 访问的应用级别的参数
53. ‘params’ => require(dirname(__FILE__) . ‘/params.php’),
54. // 在 params.php 中你需要返回这个数组:Yii::app()->setParams设置的只能用Yii::app()->params[‘xxx’]这种数组的方式访问
55. // return array(‘adminEmail’=>’info@example.com’);
56.
57. // 应用组件的配置
58. ‘components’ => array(
59. // assets, 参考www.yiiframework.com/doc/api/CAssetManager
60. ‘assetManager’ => array(
61. // 改变磁盘上的路径
62. ‘basePath’ => dirname(__FILE__) . ‘/../../assets/’,
63. // 改变url
64. ‘baseUrl’ => ‘/web/assets/’
65. ),
66. ‘request’ => array(
67. ‘enableCsrfValidation’ => true, //如果防止post跨站攻击
68. ‘enableCookieValidation’ => true, //防止Cookie攻击
69. ),
70. // 缓存
71. ‘cache’ => array(
72. ‘class’ => ‘A cache class, like: system.caching.CApcCache’,
73. ),
74. ‘session’ => array( // memcache session cache
75. ‘class’ => ‘CCacheHttpSession’,
76. ‘autoStart’ => 1,
77. ‘sessionName’ => ‘frontend’,
78. ‘cookieParams’ => array(‘lifetime’ => ‘3600’, ‘path’ => ‘/’, ‘domain’ => ‘.test.com’, ‘httponly’ => ‘1’),
79. ‘cookieMode’ => ‘only’,
80. ),
81. // 你可以使用 scriptMap 来配置脚本来自哪里。
82. // 对于一个生产环境的配置,如下
83. ‘clientScript’ => array(
84. ‘scriptMap’ => array(
85. ‘register.js’ => ‘site.min.js’,
86. ‘login.js’ => ‘site.min.js’,
87. ),
88. ),
89. // 对于一个开发环境,可以这样做
90. ‘clientScript’ => array(
91. ‘scriptMap’ => array(
92. ‘register.js’ => ‘register.js’,
93. ‘login.js’ => ‘login.js’,
94. ),
95. ),
96. ),
97.);
98.$database = require(dirname(__FILE__) . DIRECTORY_SEPARATOR . ‘db.php’);
99.if (!empty($database)) {
100. $config[‘components’] = CMap::mergeArray($config[‘components’],$database);
101.// Yii::app()->setComponents($database);
102.}
103.return $config;
// 取消下行的注释,来定义一个路径别名
// Yii::setPathOfAlias('local','path/to/local-folder');

// 这是 Web 应用配置的主体部分。任何可写的
// CWebApplication 属性可以在这里配置。
$config = array(
// protected 目录的基础路径
// 使用 Yii::app()->basePath 来访问
‘basePath’ => dirname(__FILE__) . DIRECTORY_SEPARATOR . ‘..’,

// 应用的名字
// 使用 Yii::app()->name 来访问
‘name’ => ‘My website’,

//路径别名
// 可以是应用内部的路径,也可以是外部资源
‘aliases’ => array(
‘myExternalFramework’ => dirname(__FILE__) . DIRECTORY_SEPARATOR . ‘..’ . DIRECTORY_SEPARATOR . ‘..’ . DIRECTORY_SEPARATOR . ‘myexternalframework’
),
//维护程序时,这样子所有的请求转发到一个地方
‘catchAllRequest’ => array(‘site/all’),

//如何在应用程序处理请求之前执行一段操作?当然这个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-8′,

// 预载入的应用组件
‘preload’ => array(‘log’),

// 自动载入的类
‘import’ => array(
‘application.models.*’,
‘application.components.*’,
),

// 可以使用 Yii::app()->params[‘paramName’] 访问的应用级别的参数
‘params’ => require(dirname(__FILE__) . ‘/params.php’),
// 在 params.php 中你需要返回这个数组:Yii::app()->setParams设置的只能用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 来配置脚本来自哪里。
// 对于一个生产环境的配置,如下
‘clientScript’ => array(
‘scriptMap’ => array(
‘register.js’ => ‘site.min.js’,
‘login.js’ => ‘site.min.js’,
),
),
// 对于一个开发环境,可以这样做
‘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);
// Yii::app()->setComponents($database);
}
return $config;db.php

Java代码
1. 2.return array(
3. 'db' => array(
4. ‘connectionString’ => ‘mysql:host=192.168.1.240;dbname=tttt’,
5. ‘emulatePrepare’ => true,
6. ‘username’ => ‘root’,
7. ‘password’ => ‘****’,
8. ‘charset’ => ‘utf8′,
9. ),
10. ‘card’ => array(
11. ‘class’ => ‘CDbConnection’,//
12. ‘connectionString’ => ‘mysql:host=192.168.1.240;dbname=card’,
13. ‘emulatePrepare’ => true,
14. ‘username’ => ‘root’,
15. ‘password’ => ‘**’,
16. ‘charset’ => ‘utf8′,
17. ),
18.);
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

Java代码
1. 2.return array(
3. 'adminEmail'=>‘info@example.com’,
4. ‘pagesize’=>’100′,
5. ‘pager’=>array(
6. ‘class’=>’PagerWidget’,
7. ‘maxButtonCount’=>8,
8. ‘firstPageLabel’=>’首页’,
9. ‘lastPageLabel’=>’末页’,
10. ‘nextPageLabel’=>’下一页’,
11. ‘prevPageLabel’=>’上一页’,
12. ‘header’=>”,
13. ‘cssFile’=>false,
14. ),
15.);
return array(
'adminEmail'=>‘info@example.com’,
‘pagesize’=>’100′,
‘pager’=>array(
‘class’=>’PagerWidget’,
‘maxButtonCount’=>8,
‘firstPageLabel’=>’首页’,
‘lastPageLabel’=>’末页’,
‘nextPageLabel’=>’下一页’,
‘prevPageLabel’=>’上一页’,
‘header’=>”,
‘cssFile’=>false,
),
);
index.php
配置环境常量,不同环境调用不同配置文件和调试级别。

Java代码
1./**
2. * 应用程序环境,可选:development,production,
3. */
4.defined(‘APP_ENV’) or define(‘APP_ENV’,’development’);
5.
6.// change the following paths if necessary
7.if (APP_ENV == ‘production’) {
8. error_reporting(0);
9. $yii=dirname(__FILE__).’/framework/yiilite.php';
10. defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,1);
11.} else {
12. $yii=dirname(__FILE__).’/framework/yii.php';
13. // remove the following lines when in production mode
14. defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);
15. // specify how many levels of call stack should be shown in each log message
16. defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,3);
17.}
18.$config=dirname(__FILE__).’/protected/config/’.APP_ENV.’.php';
19.require(‘path/to/globals.php’); //见附件
20.require_once($yii);
21.Yii::createWebApplication($config)->run();
/**
* 应用程序环境,可选: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);
Yii::createWebApplication($config)->run();
development.php
开启weblog,profile,数据库性能显示,数据库查询参数记录,GII

production.php
开启数据库结构缓存,关闭错误显示

Java代码
1. 2.return CMap::mergeArray(
3. require(dirname(__FILE__).'/main.php'),
4. array(
5. 'components'=>array(
6. // uncomment the following to use a MySQL database
7. ‘log’=>array(
8. ‘class’=>’CLogRouter’,
9. ‘routes’=>array(
10. array(
11. ‘class’=>’CFileLogRoute’,
12. ‘levels’=>’error, warning’,
13. )
14. ),
15. ),
16. ),
17. )
18.);

用YIIFramework的库开发 Java代码 1….. 2.Yii::createWebApp […]

  1. 还没有评论
评论提交中, 请稍候...

留言

(Spamcheck Enabled)

Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks