欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

protect/config/mian.php

程序员文章站 2024-02-15 18:51:40
...

用YIIFramework的库开发 .... Yii::createWebApplication($config); //没有run Yii::import(class1,true),在将class1类文件路径存储时,同时include该文件 注意:你也可以将配置文件分为多个文件, //例如:db.php,params.php等等 main.php ?php //取消下

用YIIFramework的库开发


  1. ....
  2. Yii::createWebApplication($config); //没有run

Yii::import(class1,true),在将class1类文件路径存储时,同时include该文件

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

main.php


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

db.php

Java代码 protect/config/mian.php

  1. return array(
  2. 'db' => array(
  3. 'connectionString' => 'mysql:host=192.168.1.240;dbname=tttt',
  4. 'emulatePrepare' => true,
  5. 'username' => 'root',
  6. 'password' => '****',
  7. 'charset' => 'utf8',
  8. ),
  9. 'card' => array(
  10. 'class' => 'CDbConnection',//
  11. 'connectionString' => 'mysql:host=192.168.1.240;dbname=card',
  12. 'emulatePrepare' => true,
  13. 'username' => 'root',
  14. 'password' => '**',
  15. 'charset' => 'utf8',
  16. ),
  17. );

params.php

Java代码 protect/config/mian.php

  1. return array(
  2. 'adminEmail'=>'info@example.com',
  3. 'pagesize'=>'100',
  4. 'pager'=>array(
  5. 'class'=>'PagerWidget',
  6. 'maxButtonCount'=>8,
  7. 'firstPageLabel'=>'首页',
  8. 'lastPageLabel'=>'末页',
  9. 'nextPageLabel'=>,
  10. 'prevPageLabel'=>,
  11. 'header'=>'',
  12. 'cssFile'=>false,
  13. ),
  14. );

index.php
配置环境常量,不同环境调用不同配置文件和调试级别。

Java代码 protect/config/mian.php

  1. /**
  2. * 应用程序环境,可选:development,production,
  3. */
  4. defined('APP_ENV') or define('APP_ENV','development');
  5. // change the following paths if necessary
  6. if (APP_ENV == 'production') {
  7. error_reporting(0);
  8. $yii=dirname(__FILE__).'/framework/yiilite.php';
  9. defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',1);
  10. } else {
  11. $yii=dirname(__FILE__).'/framework/yii.php';
  12. // remove the following lines when in production mode
  13. defined('YII_DEBUG') or define('YII_DEBUG',true);
  14. // specify how many levels of call stack should be shown in each log message
  15. defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
  16. }
  17. $config=dirname(__FILE__).'/protected/config/'.APP_ENV.'.php';
  18. require('path/to/globals.php'); //见附件
  19. require_once($yii);
  20. Yii::createWebApplication($config)->run();

development.php
开启weblog,profile,数据库性能显示,数据库查询参数记录,GII

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

Java代码 protect/config/mian.php

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

// cwebapplication属性可以在这里配置
return array(
// 使用 Yii::app()->basePath 来访问
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
// 应用的名字
// 使用 Yii::app()->name 来访问
'name'=>'OPTIMAD',
//国际化(用户语言)
'language' =>'zh_cn',


// preloading 'log' component
//预加载的日志组件
'preload'=>array('log'),


// autoloading model and component classes
//自动加载模型和组件类
'import'=>array(
'application.models.*',
'application.components.*',
),


'modules'=>array(
// uncomment the following to enable the Gii tool
'admin',
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),

),

// application components
//应用程序组件
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable URLs in path-format
/*
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'/'=>'/view',
'//'=>'/',
'/'=>'/',
),
),
*/
/*
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
*/
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=test',
'emulatePrepare' => true,
'username' => 'root',
'password' => '123',
'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',
),

//显示网页日志消息,正常情况下关掉
array(
'class'=>'CWebLogRoute',
),

),
),
),

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
//应用层参数可以访问
'params'=>array(
// 用在联系页面
'adminEmail'=>'webmaster@example.com',
),
);