Protect/config/mian. php

Source: Internet
Author: User
Use the YIIFramework library for development .... yii: createWebApplication ($ config); there is no runYii: import (class1, true). When storing the class1 class file path, also include this file. Note: you can also divide the configuration file into multiple files, such as db. php, params. php and so on main. php? Cancel php

Use the YIIFramework library for development .... yii: createWebApplication ($ config); // No run Yii: import (class1, true). When storing class1 class file paths, include the file. Note: you can also divide the configuration file into multiple files, // For example, db. php, params. php and so on main. php? Php // cancel

Use the YIIFramework library for development


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

Yii: import (class1, true). When the class1 class file path is stored, the file is also included.

Note: You can also divide the configuration file into multiple files, // For example, db. php, params. php, and so on.

Main. php


  1. // Cancel the downstream comment to define a path alias
  2. // Yii: setPathOfAlias ('local', 'path/to/local-folder ');
  3. // This is the main part of Web application configuration. Any writable
  4. // The CWebApplication attribute can be configured here.
  5. $ Config = array (
  6. // Basic path of the protected directory
  7. // Use Yii: app ()-> basePath to access
  8. 'Basepath' => dirname (_ FILE _). DIRECTORY_SEPARATOR .'..',
  9. // Application name
  10. // Use Yii: app ()-> name for access
  11. 'Name' => 'my website ',
  12. // Path alias
  13. // It can be an internal application path or an external resource
  14. 'Aliases' => array (
  15. 'Myexternalframework' => dirname (_ FILE _). DIRECTORY_SEPARATOR. '...'. DIRECTORY_SEPARATOR. '...'. DIRECTORY_SEPARATOR. 'myexternalframework'
  16. ),
  17. // During program maintenance, all such requests are forwarded to one place
  18. 'Catchallrequest' => array ('site/all '),
  19. // How do I perform an operation before the application processes the request? Of course, this function method must have index. php.
  20. 'Onbeginrequest' => 'function ',
  21. // Controller path
  22. 'Controllermap' => array ('mycontroller' => 'myexternalframework. controllers. mycontroller '),
  23. // Default controller
  24. 'Defaultcontroller' => 'SITE ',
  25. // User language (for Locale)
  26. 'Language' => 'els ',
  27. // Information and view Language
  28. 'Sourcelanguage' => 'els ',
  29. 'Timezone '=> 'Asia/Shanghai ',
  30. 'Theme '=> 'default ',
  31. // Character set used
  32. 'Charset' => 'utf-8 ',
  33. // Pre-loaded application components
  34. 'Preload' => array ('log '),
  35. // Automatically loaded class
  36. 'Import' => array (
  37. 'Application. models .*',
  38. 'Application. components .*',
  39. ),
  40. // You can use Yii: app ()-> params ['paramname'] to access application-level Parameters
  41. 'Params' => require (dirname (_ FILE _). '/params. php '),
  42. // In params. in php, you need to return this array: Yii: app ()-> setParams, which can only be accessed using the array Yii: app ()-> params ['xxx '].
  43. // Return array ('adminemail '=> 'info @ example.com ');
  44. // Configure application components
  45. 'Components' => array (
  46. // Assets, see www.yiiframework.com/doc/api/CAssetManager
  47. 'Assetmanager' => array (
  48. // Change the path on the disk
  49. 'Basepath' => dirname (_ FILE _). '/.../../assets /',
  50. // Change the url
  51. 'Baseurl' => '/web/assets /'
  52. ),
  53. 'Request' => array (
  54. 'Enablescsrfvalidation '=> true, // if you want to prevent cross-site post attacks
  55. 'Enablecookievalidation '=> true, // prevent Cookie attacks
  56. ),
  57. // Cache
  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. 'Cookieparms' => array ('lifetime' => '20160301', 'path' => '/', 'domain '=>' .test.com ', 'httpponly '=> '1 '),
  66. 'Cookiemode' => 'only ',
  67. ),
  68. // You can use scriptMap to configure where the script comes from.
  69. // Configure a production environment as follows:
  70. 'Clientscript' => array (
  71. 'Scriptmap' => array (
  72. 'Register. js' => 'site. min. js ',
  73. 'Login. js' => 'site. min. js ',
  74. ),
  75. ),
  76. // You can do this for a development environment
  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 code

  1. Return array (
  2. 'Db' => array (
  3. 'Connectionstring' => 'mysql: host = 192.168.1.240; dbname = tttttt ',
  4. 'Default' => 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. 'Default' => true,
  13. 'Username' => 'root ',
  14. 'Password' => '**',
  15. 'Charset' => 'utf8 ',
  16. ),
  17. );

Params. php

Java code

  1. Return array (
  2. 'Adminemail '=> 'info @ example.com ',
  3. 'Pagesize' => '123 ',
  4. 'Pager' => array (
  5. 'Class' => 'pagerwidget ',
  6. 'Maxbuttoncount' => 8,
  7. 'Firstpagelabel '=> 'homepage ',
  8. 'Lastpagelabel '=> 'last page ',
  9. 'Nextpagelabel '=>,
  10. 'Prevpagelabel '=>,
  11. 'Header' => '',
  12. 'Cssfile' => false,
  13. ),
  14. );

Index. php
Configure environment constants. Different configuration files and debugging levels are called in different environments.

Java code

  1. /**
  2. * Application environment, optional: 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 ('II _ TRACE_LEVEL ') or define ('II _ TRACE_LEVEL', 1 );
  10. } Else {
  11. $ Yii = dirname (_ FILE _). '/framework/yii. php ';
  12. // Remove the following lines when in production mode
  13. Defined ('II _ debug') or define ('II _ debug', true );
  14. // Specify how many levels of call stack shocould be shown in each log message
  15. Defined ('II _ TRACE_LEVEL ') or define ('II _ TRACE_LEVEL', 3 );
  16. }
  17. $ Config = dirname (_ FILE _). '/protected/config/'. APP_ENV. '. php ';
  18. Require ('path/to/globals. php'); // see the attachment.
  19. Require_once ($ yii );
  20. Yii: createWebApplication ($ config)-> run ();

Development. php
Enable weblog, profile, database performance display, database query parameter records, GII

Production. php
Enable database structure cache and Disable Error display

Java code

  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. );


// The cwebapplication attribute can be configured here
Return array (
// Use Yii: app ()-> basePath to access
'Basepath' => dirname (_ FILE _). DIRECTORY_SEPARATOR .'..',
// Application name
// Use Yii: app ()-> name for access
'Name' => 'optimad ',
// Internationalization (user language)
'Language' => 'zh _ cn ',


// Preloading 'log' component
// Pre-loaded log component
'Preload' => array ('log '),


// Autoloading model and component classes
// Automatically load models and component classes
'Import' => array (
'Application. models .*',
'Application. components .*',
),


'Modules' => array (
// Uncomment the following to enable the Gii tool
'Admin ',
'Giii '=> 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
// 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 ',
'Default' => true,
'Username' => 'root ',
'Password' => '123 ',
'Charset' => 'utf8 ',
),

'Errorhandler' => array (
// Use 'site/error' action to display errors
// Used to display errors
'Erroraction' => 'site/error ',
),
'Log' => array (
'Class' => 'clogrouter ',
'Routes '=> array (
Array (
'Class' => 'cfilelogroute ',
'Levels' => 'error, warning ',
),

// Display the webpage Log message and disable it normally
Array (
'Class' => 'cweblogroute ',
),

),
),
),

// Application-level parameters that can be accessed
// Using Yii: app ()-> params ['paramname']
// Application layer parameters are accessible
'Params' => array (
// Used on the contact page
'Adminemail '=> 'webmaster @ example.com ',
),
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.