用YIIFramework的库开发 .... Yii::createWebApplication($config); //没有run Yii::import(class1,true),在将class1类文件路径存储时,同时include该文件 注意:你也可以将配置文件分为多个文件, //例如:db.php,params.php等等 main.php ?php //取消下
用YIIFramework的库开发
- ....
- Yii::createWebApplication($config); //没有run
Yii::import(class1,true),在将class1类文件路径存储时,同时include该文件
注意:你也可以将配置文件分为多个文件, // 例如: db.php, params.php等等
main.php
- // 取消下行的注释,来定义一个路径别名
- // 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代码
- 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代码
- return array(
- 'adminEmail'=>'info@example.com',
- 'pagesize'=>'100',
- 'pager'=>array(
- 'class'=>'PagerWidget',
- 'maxButtonCount'=>8,
- 'firstPageLabel'=>'首页',
- 'lastPageLabel'=>'末页',
- 'nextPageLabel'=>,
- 'prevPageLabel'=>,
- 'header'=>'',
- 'cssFile'=>false,
- ),
- );
index.php
配置环境常量,不同环境调用不同配置文件和调试级别。
Java代码
- /**
- * 应用程序环境,可选: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代码
- 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',
- )
- ),
- ),
- ),
- )
- );
// 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(
'
'
'
),
),
*/
/*
'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',
),
);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools