php教程 php手册 protect/config/mian.php

protect/config/mian.php

Jun 06, 2016 pm 08:02 PM
config

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

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)