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
- ....
- 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
-
- // Cancel the downstream comment to define a path alias
- // Yii: setPathOfAlias ('local', 'path/to/local-folder ');
-
- // This is the main part of Web application configuration. Any writable
- // The CWebApplication attribute can be configured here.
- $ Config = array (
- // Basic path of the protected directory
- // Use Yii: app ()-> basePath to access
- 'Basepath' => dirname (_ FILE _). DIRECTORY_SEPARATOR .'..',
-
- // Application name
- // Use Yii: app ()-> name for access
- 'Name' => 'my website ',
-
- // Path alias
- // It can be an internal application path or an external resource
- 'Aliases' => array (
- 'Myexternalframework' => dirname (_ FILE _). DIRECTORY_SEPARATOR. '...'. DIRECTORY_SEPARATOR. '...'. DIRECTORY_SEPARATOR. 'myexternalframework'
- ),
- // During program maintenance, all such requests are forwarded to one place
- 'Catchallrequest' => array ('site/all '),
-
- // How do I perform an operation before the application processes the request? Of course, this function method must have index. php.
- 'Onbeginrequest' => 'function ',
-
- // Controller path
- 'Controllermap' => array ('mycontroller' => 'myexternalframework. controllers. mycontroller '),
-
- // Default controller
- 'Defaultcontroller' => 'SITE ',
-
- // User language (for Locale)
- 'Language' => 'els ',
-
- // Information and view Language
- 'Sourcelanguage' => 'els ',
- 'Timezone '=> 'Asia/Shanghai ',
- 'Theme '=> 'default ',
- // Character set used
- 'Charset' => 'utf-8 ',
-
- // Pre-loaded application components
- 'Preload' => array ('log '),
-
- // Automatically loaded class
- 'Import' => array (
- 'Application. models .*',
- 'Application. components .*',
- ),
-
- // You can use Yii: app ()-> params ['paramname'] to access application-level Parameters
- 'Params' => require (dirname (_ FILE _). '/params. php '),
- // 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 '].
- // Return array ('adminemail '=> 'info @ example.com ');
-
- // Configure application components
- 'Components' => array (
- // Assets, see www.yiiframework.com/doc/api/CAssetManager
- 'Assetmanager' => array (
- // Change the path on the disk
- 'Basepath' => dirname (_ FILE _). '/.../../assets /',
- // Change the url
- 'Baseurl' => '/web/assets /'
- ),
- 'Request' => array (
- 'Enablescsrfvalidation '=> true, // if you want to prevent cross-site post attacks
- 'Enablecookievalidation '=> true, // prevent Cookie attacks
- ),
- // Cache
- 'Cache' => array (
- 'Class' => 'a cache class, like: system. caching. capccache ',
- ),
- 'Session' => array (// memcache session cache
- 'Class' => 'ccachehttpsession ',
- 'Autostart' => 1,
- 'Sessionname' => 'frontend ',
- 'Cookieparms' => array ('lifetime' => '20160301', 'path' => '/', 'domain '=>' .test.com ', 'httpponly '=> '1 '),
- 'Cookiemode' => 'only ',
- ),
- // You can use scriptMap to configure where the script comes from.
- // Configure a production environment as follows:
- 'Clientscript' => array (
- 'Scriptmap' => array (
- 'Register. js' => 'site. min. js ',
- 'Login. js' => 'site. min. js ',
- ),
- ),
- // You can do this for a development environment
- '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 code
-
- Return array (
- 'Db' => array (
- 'Connectionstring' => 'mysql: host = 192.168.1.240; dbname = tttttt ',
- 'Default' => true,
- 'Username' => 'root ',
- 'Password' => '****',
- 'Charset' => 'utf8 ',
- ),
- 'Card '=> array (
- 'Class' => 'cdbconnection ',//
- 'Connectionstring' => 'mysql: host = 192.168.1.240; dbname = card ',
- 'Default' => true,
- 'Username' => 'root ',
- 'Password' => '**',
- 'Charset' => 'utf8 ',
- ),
- );
Params. php
Java code
-
- Return array (
- 'Adminemail '=> 'info @ example.com ',
- 'Pagesize' => '123 ',
- 'Pager' => array (
- 'Class' => 'pagerwidget ',
- 'Maxbuttoncount' => 8,
- 'Firstpagelabel '=> 'homepage ',
- 'Lastpagelabel '=> 'last page ',
- 'Nextpagelabel '=>,
- 'Prevpagelabel '=>,
- 'Header' => '',
- 'Cssfile' => false,
- ),
- );
Index. php
Configure environment constants. Different configuration files and debugging levels are called in different environments.
Java code
- /**
- * Application environment, optional: 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 ('II _ TRACE_LEVEL ') or define ('II _ TRACE_LEVEL', 1 );
- } Else {
- $ Yii = dirname (_ FILE _). '/framework/yii. php ';
- // Remove the following lines when in production mode
- Defined ('II _ debug') or define ('II _ debug', true );
- // Specify how many levels of call stack shocould be shown in each log message
- Defined ('II _ TRACE_LEVEL ') or define ('II _ TRACE_LEVEL', 3 );
- }
- $ Config = dirname (_ FILE _). '/protected/config/'. APP_ENV. '. php ';
- Require ('path/to/globals. php'); // see the attachment.
- Require_once ($ yii );
- 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
-
- 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 ',
- )
- ),
- ),
- ),
- )
- );
// 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 ',
),
);