博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用YIIFramework的库开发
阅读量:6878 次
发布时间:2019-06-26

本文共 4687 字,大约阅读时间需要 15 分钟。

hot3.png

用YIIFramework的库开发

Java代码  收藏代码

  1. ....  

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

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

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

main.php

Java代码  收藏代码

  1. <?php  

  2. // 取消下行的注释,来定义一个路径别名  

  3. // Yii::setPathOfAlias('local','path/to/local-folder');  

  4.   

  5. // 这是 Web 应用配置的主体部分。任何可写的  

  6. // CWebApplication 属性可以在这里配置。  

  7. $config = array(  

  8.     // protected 目录的基础路径  

  9.     // 使用 Yii::app()->basePath 来访问  

  10.     'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',  

  11.   

  12.     // 应用的名字  

  13.     // 使用 Yii::app()->name 来访问  

  14.     'name' => 'My website',  

  15.   

  16.     //路径别名  

  17.     // 可以是应用内部的路径,也可以是外部资源  

  18.     'aliases' => array(  

  19.         'myExternalFramework' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'myexternalframework'  

  20.     ),  

  21.     //维护程序时,这样子所有的请求转发到一个地方  

  22.     'catchAllRequest' => array('site/all'),  

  23.   

  24.     //如何在应用程序处理请求之前执行一段操作?当然这个function方法要存在index.php  

  25.     'onBeginRequest' => 'function',  

  26.   

  27.     //controller path  

  28.     'controllerMap' => array('myController' => 'myExternalFramework.controllers.MyController'),  

  29.   

  30.     // 默认的 controller  

  31.     'defaultController' => 'site',  

  32.   

  33.     // 用户语言(for Locale)  

  34.     'language' => 'es',  

  35.   

  36.     //信息和视图的语言  

  37.     'sourceLanguage' => 'es',  

  38.     'timeZone' => 'Asia/Shanghai',  

  39.     'theme' => 'default',  

  40.     // 使用的字符集  

  41.     'charset' => 'utf-8',  

  42.   

  43.     // 预载入的应用组件  

  44.     'preload' => array('log'),  

  45.   

  46.     // 自动载入的类  

  47.     'import' => array(  

  48.         'application.models.*',  

  49.         'application.components.*',  

  50.     ),  

  51.   

  52.     // 可以使用 Yii::app()->params['paramName'] 访问的应用级别的参数  

  53.     'params' => require(dirname(__FILE__) . '/params.php'),  

  54.     // 在 params.php 中你需要返回这个数组:Yii::app()->setParams设置的只能用Yii::app()->params['xxx']这种数组的方式访问  

  55.     // return array('adminEmail'=>'info@example.com');  

  56.   

  57.     // 应用组件的配置  

  58.     'components' => array(  

  59.         // assets, 参考www.yiiframework.com/doc/api/CAssetManager  

  60.         'assetManager' => array(  

  61.             // 改变磁盘上的路径  

  62.             'basePath' => dirname(__FILE__) . '/../../assets/',  

  63.             // 改变url  

  64.             'baseUrl' => '/web/assets/'  

  65.         ),  

  66.         'request' => array(  

  67.             'enableCsrfValidation' => true//如果防止post跨站攻击  

  68.             'enableCookieValidation' => true//防止Cookie攻击  

  69.         ),  

  70.         // 缓存  

  71.         'cache' => array(  

  72.             'class' => 'A cache class, like: system.caching.CApcCache',  

  73.         ),  

  74.         'session' => array( //  memcache session cache  

  75.             'class' => 'CCacheHttpSession',  

  76.             'autoStart' => 1,  

  77.             'sessionName' => 'frontend',  

  78.             'cookieParams' => array('lifetime' => '3600''path' => '/''domain' => '.test.com''httponly' => '1'),  

  79.             'cookieMode' => 'only',  

  80.         ),  

  81.         // 你可以使用 scriptMap 来配置脚本来自哪里。  

  82.         // 对于一个生产环境的配置,如下  

  83.         'clientScript' => array(  

  84.             'scriptMap' => array(  

  85.                 'register.js' => 'site.min.js',  

  86.                 'login.js' => 'site.min.js',  

  87.             ),  

  88.         ),  

  89.         // 对于一个开发环境,可以这样做  

  90.         'clientScript' => array(  

  91.             'scriptMap' => array(  

  92.                 'register.js' => 'register.js',  

  93.                 'login.js' => 'login.js',  

  94.             ),  

  95.         ),  

  96.     ),  

  97. );  

  98. $database =  require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'db.php');  

  99. if (!empty($database)) {  

  100.     $config['components'] = CMap::mergeArray($config['components'],$database);  

  101. //    Yii::app()->setComponents($database);  

  102. }  

  103. return $config;  

db.php

Java代码  收藏代码

  1. <?php  

  2. return array(  

  3.     'db' => array(  

  4.         'connectionString' => 'mysql:host=192.168.1.240;dbname=tttt',  

  5.         'emulatePrepare' => true,  

  6.         'username' => 'root',  

  7.         'password' => '****',  

  8.         'charset' => 'utf8',  

  9.     ),  

  10.     'card' => array(  

  11.         'class' => 'CDbConnection',//  

  12.         'connectionString' => 'mysql:host=192.168.1.240;dbname=card',  

  13.         'emulatePrepare' => true,  

  14.         'username' => 'root',  

  15.         'password' => '**',  

  16.         'charset' => 'utf8',  

  17.     ),  

  18. );  

params.php

Java代码  收藏代码

  1. <?php  

  2. return array(  

  3.     'adminEmail'=>'info@example.com',  

  4.     'pagesize'=>'100',  

  5.     'pager'=>array(  

  6.         'class'=>'PagerWidget',   

  7.         'maxButtonCount'=>8,  

  8.         'firstPageLabel'=>'首页',  

  9.         'lastPageLabel'=>'末页',  

  10.         'nextPageLabel'=>'下一页',  

  11.         'prevPageLabel'=>'上一页',  

  12.         'header'=>'',  

  13.         'cssFile'=>false,   

  14.     ),   

  15. );   

index.php 

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

Java代码  收藏代码

  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代码  收藏代码

  1. <?php  

  2. return CMap::mergeArray(  

  3.     require(dirname(__FILE__).'/main.php'),  

  4.     array(  

  5.         'components'=>array(  

  6.             // uncomment the following to use a MySQL database  

  7.             'log'=>array(  

  8.                 'class'=>'CLogRouter',  

  9.                 'routes'=>array(  

  10.                     array(  

  11.                         'class'=>'CFileLogRoute',  

  12.                         'levels'=>'error, warning',  

  13.                     )  

  14.                 ),  

  15.             ),  

  16.         ),  

  17.     )  

  18. );  

转载于:https://my.oschina.net/yonghan/blog/597795

你可能感兴趣的文章
Cocos2d-x--Box2D使用GLES-Render.h渲染查看刚体
查看>>
图片阴影效果和影子效果
查看>>
windows7引导故障的解决
查看>>
妹子与汉子——引用与指针的区别(1)
查看>>
我的友情链接
查看>>
python Day 4 :员工信息表/ATM+购物车/计算器
查看>>
LNMP 配置NGINX 支持THINKPHP PATHINFO模式
查看>>
Ubuntu 下让sublime-text3支持中文输入法
查看>>
我的友情链接
查看>>
Linux运维异常
查看>>
centos7.6快速搭建lamp环境调试过程
查看>>
ulimit 参数详解及配置文件说明
查看>>
Spring boot 总结之跨域处理cors
查看>>
socektpair
查看>>
Scala java maven 混合开发 pom配置
查看>>
Golang计算MD5
查看>>
我的友情链接
查看>>
Pypy对Python的提速
查看>>
ubuntu 13.04连接wpa无线
查看>>
java,SimpleDateFormat,时间格式化
查看>>