首页 技术 正文
技术 2022年11月11日
0 收藏 891 点赞 2,164 浏览 4431 个字

用YIIFramework的库开发

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

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

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

main.php

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

db.php

  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

  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 
配置环境常量,不同环境调用不同配置文件和调试级别。

  1. /**
  2. * 应用程序环境,可选: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(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,1);
  10. } else {
  11. $yii=dirname(__FILE__).’/framework/yii.php’;
  12. // remove the following lines when in production mode
  13. defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);
  14. // specify how many levels of call stack should be shown in each log message
  15. defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,3);
  16. }
  17. $config=dirname(__FILE__).’/protected/config/’.APP_ENV.’.php’;
  18. require(‘path/to/globals.php’); //见附件
  19. require_once($yii);
  20. Yii::createWebApplication($config)->run();

development.php 
开启weblog,profile,数据库性能显示,数据库查询参数记录,GII

production.php 
开启数据库结构缓存,关闭错误显示

    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. );
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898