Yii 配置信息 配置项(Configuration)

  1 配置项(Configuration)
  2
  3 说到配置项,读者朋友们第一反应是不是Yii的配置文件?这是一段配置文件的代码:
  4
  5  1
  6  2
  7  3
  8  4
  9  5
 10  6
 11  7
 12  8
 13  9
 14 10
 15 11
 16 12
 17 13
 18 14
 19 15
 20 16
 21 17
 22 18
 23 19
 24 20
 25 21
 26 22
 27 23
 28 24
 29 25
 30 26
 31 27
 32 28
 33 29
 34 30
 35 31
 36 32
 37 33
 38 34
 39
 40
 41
 42 return [
 43     ‘id‘ => ‘app-frontend‘,
 44     ‘basePath‘ => dirname(__DIR__),
 45     ‘bootstrap‘ => [‘log‘],
 46     ‘controllerNamespace‘ => ‘frontend\controllers‘,
 47
 48     ‘components‘ => [
 49         ‘db‘ => [
 50             ‘class‘ => ‘yii\db\Connection‘,
 51             ‘dsn‘ => ‘mysql:host=localhost;dbname=yii2advanced‘,
 52             ‘username‘ => ‘root‘,
 53             ‘password‘ => ‘‘,
 54             ‘charset‘ => ‘utf8‘,
 55         ],
 56         ... ...
 57         ‘cache‘ => [
 58             ‘class‘ => ‘yii\caching\MemCache‘,
 59             ‘servers‘ => [
 60                 [
 61                     ‘host‘ => ‘cache1.digpage.com‘,
 62                     ‘port‘ => 11211,
 63                     ‘weight‘ => 60,
 64                 ],
 65                 [
 66                     ‘host‘ => ‘cache2.digpage.com‘,
 67                     ‘port‘ => 11211,
 68                     ‘weight‘ => 40,
 69                 ],
 70             ],
 71         ],
 72     ],
 73
 74     ‘params‘ => [...],
 75 ];
 76
 77 Yii中许多地方都要用到配置项,Yii应用自身和其他几乎一切类对象的创建、初始化、配置都要用到配置项。 配置项是针对对象而言的,也就是说,配置项一定是用于配置某一个对象,用于初始化或配置对象的属性。 关于属性的有关内容,请查看 属性(Property) 。
 78 配置项的格式
 79
 80 一个配置文件包含了3个部分:
 81
 82     基本信息配置。主要指如 id basePath 等这些应用的基本信息,主要是一些简单的字符串。
 83     components配置。配置文件的主体,也是我们接下来要讲的配置项。
 84     params配置。主要是提供一些全局参数。
 85
 86 我们一般讲的配置项是指component配置项及里面的子项。 简单来讲,一个配置项采用下面的格式:
 87
 88 1
 89 2
 90 3
 91 4
 92 5
 93 6
 94
 95
 96
 97 [
 98     ‘class‘ => ‘path\to\ClassName‘,
 99     ‘propertyName‘ => ‘propertyValue‘,
100     ‘on eventName‘ => $eventHandler,
101     ‘as behaviorName‘ => $behaviorConfig,
102 ]
103
104 作为配置项:
105
106     配置项以数组进行组织。
107     class 数组元素表示将要创建的对象的完整类名。
108     propertyName 数组元素表示指定为 propertyName 属性的初始值为 $propertyValue 。
109     on eventName 数组元素表示将 $eventHandler 绑定到对象的 eventName 事件中。
110     as behaviorName 数组元素表示用 $behaviorConfig 创建一个行为,并注入到对象中。 这里的 $behaviroConfig 也是一个配置项;
111     配置项可以嵌套。
112
113 其中, class 元素仅在特定的情况下可以没有。就是使用配置数组的时候,其类型已经是确定的。 这往往是用于重新配置一个已经存在的对象, 或者是在创建对象时,使用了 new 或 Yii::createObject() 指定了类型。 除此以外的大多数情况 class 都是配置数组的必备元素:
114
115  1
116  2
117  3
118  4
119  5
120  6
121  7
122  8
123  9
124 10
125 11
126 12
127 13
128 14
129 15
130 16
131 17
132 18
133 19
134 20
135 21
136 22
137 23
138
139
140
141 // 使用 new 时指定了类型,配置数组中就不应再有 class 元素
142 $connection = new \yii\db\Connection([
143     ‘dsn‘ => $dsn,
144     ‘username‘ => $username,
145     ‘password‘ => $password,
146 ]);
147
148 // 使用 Yii::createObject()时,如果第一个参数指定了类型,也不应在配置数
149 // 组中设定 class
150 $db = Yii::createObject(‘yii\db\Connection‘, [
151      ‘dsn‘ => ‘mysql:host=127.0.0.1;dbname=demo‘,
152      ‘username‘ => ‘root‘,
153      ‘password‘ => ‘‘,
154      ‘charset‘ => ‘utf8‘,
155 ]);
156
157 // 对现有的对象重新配置时,也不应在配置数组中设定 class
158 Yii::configure($db, [
159      ‘dsn‘ => ‘mysql:host=127.0.0.1;dbname=demo‘,
160      ‘username‘ => ‘root‘,
161      ‘password‘ => ‘‘,
162      ‘charset‘ => ‘utf8‘,
163 ]);
164
165 上面的例子中,在没看到配置数组的内容前,已经可以确定对象的类型了。 这种其他情况下,配置数组中如果再有一个 class 元素来设定类型的话,就不合理了。 这种情况下,配置数组不能有 class 元素。 但除此以外的其他情况,均要求配置数组提供 class 元素,以表示要创建的对象的类型。
166 配置项产生作用的原理
167
168 从 环境和配置文件 部分的内容,我们了解到了一个Yii应用,特别是高级模版应用,是具有许多个配置文件的, 这些配置文件在入口脚本 index.php 中被引入, 然后按照一定的规则合并成一个配置数组 $config 并用于创建Application对象。 具体可以看看 入口文件index.php 部分的内容。在入口脚本中,调用了:
169
170 $application = new yii\web\Application($config);
171
172 在 yii\web\Application 中,会调用父类的构造函数 yii\base\Application::__construct($config) , 来创建Web Application。在这个构造函数中:
173
174  1
175  2
176  3
177  4
178  5
179  6
180  7
181  8
182  9
183 10
184 11
185 12
186 13
187 14
188 15
189
190
191
192 public function __construct($config = [])
193 {
194     Yii::$app = $this;
195     $this->setInstance($this);
196
197     $this->state = self::STATE_BEGIN;
198
199     // 预处理配置项
200     $this->preInit($config);
201
202     $this->registerErrorHandler($config);
203
204     // 使用 yii\base\Component::__construct() 完成构建
205     Component::__construct($config);
206 }
207
208 可以看到,其实分成两步,一是对 $config 进行预处理, 二是使用 yii\base\Component::__construct($config) 进行构建。
209 配置项预处理
210
211 预处理配置项的 yii\base\Application::preInit() 方法其实在 别名(Alias) 部分讲过, 当时主要是从预定义别名的角度来讲的。现在我们再来完整地看看这个方法和有关的属性:
212
213  1
214  2
215  3
216  4
217  5
218  6
219  7
220  8
221  9
222 10
223 11
224 12
225 13
226 14
227 15
228 16
229 17
230 18
231 19
232 20
233 21
234 22
235 23
236 24
237 25
238 26
239 27
240 28
241 29
242 30
243 31
244 32
245 33
246 34
247 35
248 36
249 37
250 38
251 39
252 40
253 41
254 42
255 43
256 44
257 45
258 46
259 47
260 48
261 49
262 50
263 51
264 52
265 53
266 54
267 55
268 56
269 57
270 58
271 59
272 60
273 61
274 62
275 63
276 64
277 65
278 66
279 67
280 68
281 69
282 70
283 71
284 72
285
286
287
288 // basePath属性,由Application的父类yii\base\Module定义,并提供getter和setter
289 private $_basePath;
290
291 // runtimePath属性和vendorPath属性,Application都为其定义了getter和setter。
292 private $_runtimePath;
293 private $_vendorPath;
294
295 // 还有一个timeZone属性,Application为其提供了getter和setter,但不提供存
296 // 储变量。
297 // 而是分别调用 PHP 的 date_default_timezone_get() 和
298 // date_default_timezone_set()
299
300 public function preInit(&$config)
301 {
302     // 配置数组中必须指定应用id,这里仅判断,不赋值。
303     if (!isset($config[‘id‘])) {
304         throw new InvalidConfigException(
305             ‘The "id" configuration for the Application is required.‘);
306     }
307
308     // 设置basePath属性,这个属性在Application的父类 yii\base\Module 中定义。
309     // 在完成设置后,删除配置数组中的 basePath 配置项
310     if (isset($config[‘basePath‘])) {
311         $this->setBasePath($config[‘basePath‘]);
312         unset($config[‘basePath‘]);
313     } else {
314         throw new InvalidConfigException(
315         ‘The "basePath" configuration for the Application is required.‘);
316     }
317
318     // 设置vendorPath属性,并在设置后,删除$config中的相应配置项
319     if (isset($config[‘vendorPath‘])) {
320         $this->setVendorPath($config[‘vendorPath‘]);
321         unset($config[‘vendorPath‘]);
322     } else {
323         // set "@vendor"
324         $this->getVendorPath();
325     }
326
327     // 设置runtimePath属性,并在设置后,删除$config中的相应配置项
328     if (isset($config[‘runtimePath‘])) {
329         $this->setRuntimePath($config[‘runtimePath‘]);
330         unset($config[‘runtimePath‘]);
331     } else {
332         // set "@runtime"
333         $this->getRuntimePath();
334     }
335
336     // 设置timeZone属性,并在设置后,删除$config中的相应配置项
337     if (isset($config[‘timeZone‘])) {
338         $this->setTimeZone($config[‘timeZone‘]);
339         unset($config[‘timeZone‘]);
340     } elseif (!ini_get(‘date.timezone‘)) {
341         $this->setTimeZone(‘UTC‘);
342     }
343
344     // 将coreComponents() 所定义的核心组件配置,与开发者通过配置文件定义
345     // 的组件配置进行合并。
346     // 合并中,开发者配置优先,核心组件配置起补充作用。
347     foreach ($this->coreComponents() as $id => $component) {
348
349         // 配置文件中没有的,使用核心组件的配置
350         if (!isset($config[‘components‘][$id])) {
351             $config[‘components‘][$id] = $component;
352
353         // 配置文件中有的,但并未指组件的class的,使用核心组件的class
354         } elseif (is_array($config[‘components‘][$id]) &&
355             !isset($config[‘components‘][$id][‘class‘])) {
356             $config[‘components‘][$id][‘class‘] = $component[‘class‘];
357         }
358     }
359 }
360
361 从上面的代码可以看出,这个 preInit() 对配置数组 $config 作了以下处理:
362
363     id 属性是必不可少的。
364     从 $config 中拿掉了 basePath runtimePath vendorPath 和 timeZone 4个属性的配置项。 当然,也设置了相应的属性。
365     对 $config[‘components‘] 配置项进行两方面的补充。 一是配置文件中没有的,而核心组件有的,把核心组件的配置信息补充进去。 二是配置文件中虽然也有,但没有指定组件的class的,使用核心组件配置信息指定的class。
366
367 基于此,我们不难得出如下结论:
368
369     有的配置项如 id 是不可少的,有的配置项如 basePath 等不用我们设置也是有默认值的。
370     对于核心组件,我们不配置也可以使用。
371     核心组件的ID是提前安排好的,没有充足的理由一般不要改变他,否则以后接手的人会骂你的。
372     核心组件可以不指明 class ,默认会使用预先安排的类型。
373
374 对于核心组件,不同的应用有不同的安排,这个我们可以看看,大致了解下,具体在于各应用的 coreComponents() 中定义:
375
376  1
377  2
378  3
379  4
380  5
381  6
382  7
383  8
384  9
385 10
386 11
387 12
388 13
389 14
390 15
391 16
392 17
393 18
394 19
395 20
396 21
397 22
398 23
399 24
400 25
401 26
402 27
403 28
404 29
405 30
406 31
407 32
408 33
409 34
410 35
411 36
412
413
414
415 // yii\base\Application 的核心组件
416 public function coreComponents()
417 {
418     return [
419         ‘log‘ => [‘class‘ => ‘yii\log\Dispatcher‘],             // 日志组件
420         ‘view‘ => [‘class‘ => ‘yii\web\View‘],                  // 视图组件
421         ‘formatter‘ => [‘class‘ => ‘yii\i18n\Formatter‘],       // 格式组件
422         ‘i18n‘ => [‘class‘ => ‘yii\i18n\I18N‘],                 // 国际化组件
423         ‘mailer‘ => [‘class‘ => ‘yii\swiftmailer\Mailer‘],      // 邮件组件
424         ‘urlManager‘ => [‘class‘ => ‘yii\web\UrlManager‘],      // url管理组件
425         ‘assetManager‘ => [‘class‘ => ‘yii\web\AssetManager‘],  // 前端资源管理组件
426         ‘security‘ => [‘class‘ => ‘yii\base\Security‘],         // 安全组件
427     ];
428 }
429
430 // yii\web\Application 的核心组件,在基类的基础上加入Web应用必需的组件
431 public function coreComponents()
432 {
433     return array_merge(parent::coreComponents(), [
434         ‘request‘ => [‘class‘ => ‘yii\web\Request‘],            // HTTP请求组件
435         ‘response‘ => [‘class‘ => ‘yii\web\Response‘],          // HTTP响应组件
436         ‘session‘ => [‘class‘ => ‘yii\web\Session‘],            // session组件
437         ‘user‘ => [‘class‘ => ‘yii\web\User‘],                  // 用户管理组件
438         ‘errorHandler‘ => [‘class‘ => ‘yii\web\ErrorHandler‘],  // 错误处理组件
439     ]);
440 }
441
442 // yii\console\Application 的核心组件,
443 public function coreComponents()
444 {
445     return array_merge(parent::coreComponents(), [
446         ‘request‘ => [‘class‘ => ‘yii\console\Request‘],        // 命令行请求组件
447         ‘response‘ => [‘class‘ => ‘yii\console\Response‘],      // 命令行响应组件
448         ‘errorHandler‘ => [‘class‘ => ‘yii\console\ErrorHandler‘], // 错误处理组件
449     ]);
450 }
451
452 这些我们大致有个印象就够了,不用刻意去记住,用着用着你就自然记住了。
453 使用配置数组构造应用
454
455 在使用 preInit() 完成配置数组的预处理之后, Application构造函数又直接调用 yii\base\Component::__construct() 来构造Application对象。
456
457 结果这个 yii\base\Component::__construct() 也是个推委扯皮的家伙,他根本就没自己定义。 而是直接继承了父类的 yii\base\Object::__construct() 。因此,Application构造函数的最后一步, 实际上调用的是 yii\base\Object::__construct($config) 。 这个函数的原理,我们在 Object的配置方法 部分已经作出解释,这里就不再重复。
458
459 只是这里有两类特殊的配置项需要注意,就是以 on * 打头的事件和以 as * 打头的行为。 对于事件行为,可以阅读 事件(Event) 和 行为(Behavior) 部分的内容。
460
461 Yii对于这两类配置项的处理,是在 yii\base\Component::__set() 中完成的,从Component开始, 才支持事件和行为。具体处理的代码如下:
462
463  1
464  2
465  3
466  4
467  5
468  6
469  7
470  8
471  9
472 10
473 11
474 12
475 13
476 14
477 15
478 16
479 17
480 18
481 19
482 20
483 21
484 22
485 23
486 24
487 25
488 26
489 27
490 28
491 29
492 30
493 31
494 32
495 33
496 34
497 35
498 36
499 37
500 38
501 39
502 40
503
504
505
506 public function __set($name, $value)
507 {
508     $setter = ‘set‘ . $name;
509     if (method_exists($this, $setter)) {
510         $this->$setter($value);
511         return;
512
513     // ‘on ‘ 打头的配置项在这里处理
514     } elseif (strncmp($name, ‘on ‘, 3) === 0) {
515
516         // 对于 ‘on event‘ 配置项,将配置值作为事件 handler 绑定到 evnet 上去
517         $this->on(trim(substr($name, 3)), $value);
518         return;
519
520     // ‘as ‘ 打头的配置项在这里处理
521     } elseif (strncmp($name, ‘as ‘, 3) === 0) {
522
523         // 对于 ‘as behavior‘ 配置项,将配置值作为创建Behavior的配置,创
524         // 建后绑定为 behavior
525         $name = trim(substr($name, 3));
526         $this->attachBehavior($name, $value instanceof Behavior ? $value
527             : Yii::createObject($value));
528         return;
529     } else {
530         $this->ensureBehaviors();
531         foreach ($this->_behaviors as $behavior) {
532             if ($behavior->canSetProperty($name)) {
533                 $behavior->$name = $value;
534                 return;
535             }
536         }
537     }
538     if (method_exists($this, ‘get‘ . $name)) {
539         throw new InvalidCallException(‘Setting read-only property: ‘ .
540             get_class($this) . ‘::‘ . $name);
541     } else {
542         throw new UnknownPropertyException(‘Setting unknown property: ‘
543             . get_class($this) . ‘::‘ . $name);
544     }
545 }
546
547 从上面的代码中可以看到,对于 on event 形式配置项,Yii视配置值为一个事件handler,绑定到 event 上。 而对于 as behavior 形式的配置项,视配置值为一个Behavior,注入到当前实例中,并冠以 behavior 的名称。

以上是转载的 Yii 自带的核心组件 coreComponents 分布在三个位置 如下:
 1 // yii\base\Application 的核心组件
 2 public function coreComponents()
 3 {
 4     return [
 5         ‘log‘ => [‘class‘ => ‘yii\log\Dispatcher‘],             // 日志组件
 6         ‘view‘ => [‘class‘ => ‘yii\web\View‘],                  // 视图组件
 7         ‘formatter‘ => [‘class‘ => ‘yii\i18n\Formatter‘],       // 格式组件
 8         ‘i18n‘ => [‘class‘ => ‘yii\i18n\I18N‘],                 // 国际化组件
 9         ‘mailer‘ => [‘class‘ => ‘yii\swiftmailer\Mailer‘],      // 邮件组件
10         ‘urlManager‘ => [‘class‘ => ‘yii\web\UrlManager‘],      // url管理组件
11         ‘assetManager‘ => [‘class‘ => ‘yii\web\AssetManager‘],  // 前端资源管理组件
12         ‘security‘ => [‘class‘ => ‘yii\base\Security‘],         // 安全组件
13     ];
14 }
15
16 // yii\web\Application 的核心组件,在基类的基础上加入Web应用必需的组件
17 public function coreComponents()
18 {
19     return array_merge(parent::coreComponents(), [
20         ‘request‘ => [‘class‘ => ‘yii\web\Request‘],            // HTTP请求组件
21         ‘response‘ => [‘class‘ => ‘yii\web\Response‘],          // HTTP响应组件
22         ‘session‘ => [‘class‘ => ‘yii\web\Session‘],            // session组件
23         ‘user‘ => [‘class‘ => ‘yii\web\User‘],                  // 用户管理组件
24         ‘errorHandler‘ => [‘class‘ => ‘yii\web\ErrorHandler‘],  // 错误处理组件
25     ]);
26 }
27
28 // yii\console\Application 的核心组件,
29 public function coreComponents()
30 {
31     return array_merge(parent::coreComponents(), [
32         ‘request‘ => [‘class‘ => ‘yii\console\Request‘],        // 命令行请求组件
33         ‘response‘ => [‘class‘ => ‘yii\console\Response‘],      // 命令行响应组件
34         ‘errorHandler‘ => [‘class‘ => ‘yii\console\ErrorHandler‘], // 错误处理组件
35     ]);
36 }

项目里面的配置文件信息如下:

web.php 的配置文件 配置了redis 、极光推送、

  1 <?php
  2
  3 $params = require(__DIR__ . ‘/params.php‘);
  4
  5 $config = [
  6     ‘id‘ => ‘basic‘,
  7     ‘basePath‘ => dirname(__DIR__),
  8     ‘bootstrap‘ => [‘log‘],
  9     ‘language‘ => ‘zh-CN‘,
 10     ‘timeZone‘ => ‘Asia/Chongqing‘,
 11     ‘controllerMap‘ => [
 12
 13         ‘apiswagger‘ => [
 14
 15             ‘class‘ => ‘app\apis\ApiSwaggerController‘
 16         ]
 17     ],
 18     ‘components‘ => [
 19         ‘request‘ => [
 20             // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
 21             ‘cookieValidationKey‘ => ‘SKLFKL123GJKJ_3209JSALKFJAJLKSJ‘,
 22         ],
 23         ‘cache‘ => [
 24             ‘class‘ => ‘yii\caching\FileCache‘,
 25         ],
 26         ‘redis‘ => [
 27             ‘class‘ => ‘yii\redis\Connection‘,
 28             ‘hostname‘ => ‘192.168.1.252‘,
 29             ‘port‘ => 6379,
 30             ‘database‘ => 0,
 31         ],
 32         ‘jpush‘ => [
 33             ‘class‘ => ‘lspbupt\Jpush\Jpush‘,
 34             ‘app_key‘ => "cc6642c4b4415055958192f6", //极光推送的appkey
 35             ‘app_secret‘ => "f2e3fe01f1370cb12fd08748", //极光推送的appsecret
 36         ],
 37         ‘session‘ => [
 38             ‘class‘ => ‘yii\redis\Session‘,
 39             ‘redis‘ => [
 40                 ‘hostname‘ => ‘192.168.1.252‘,
 41                 ‘port‘ => 6379,
 42                 ‘database‘ => 0,
 43             ],
 44             ‘keyPrefix‘=>‘users:‘
 45         ],
 46         ‘user‘ => [
 47             ‘identityClass‘ => ‘app\models\User‘,
 48             ‘enableAutoLogin‘ => true,
 49             ‘loginUrl‘ => [‘site/login‘],
 50             ‘idParam‘ => ‘__user‘,
 51             ‘identityCookie‘ => [‘name‘ => ‘__user_identity‘, ‘httpOnly‘ => true],
 52         ],
 53         ‘manage‘ => [
 54             ‘class‘ => ‘yii\web\User‘,
 55             ‘identityClass‘ => ‘app\modules\manage\models\User‘,
 56             ‘enableAutoLogin‘ => true,
 57             ‘loginUrl‘ => [‘manage/user/login‘],
 58             ‘idParam‘ => ‘__Manage‘,
 59             ‘identityCookie‘ => [‘name‘ => ‘__Manage_identity‘, ‘httpOnly‘ => true],
 60 //            ‘autoRenewCookie‘=> false
 61         ],
 62         ‘company‘ =>
 63             [
 64                 ‘class‘ => ‘app\components\Company‘,
 65             ],
 66         ‘userAuth‘ =>
 67             [
 68                 ‘class‘ => ‘app\components\UserAuth‘,
 69             ],
 70 //        ‘errorHandler‘ => [
 71 //            ‘errorAction‘ => ‘site/error‘,
 72 //        ],
 73         ‘mailer‘ => [
 74             ‘class‘ => ‘yii\swiftmailer\Mailer‘,
 75             ‘viewPath‘ => ‘@common/mail‘,
 76             // send all mails to a file by default. You have to set
 77             // ‘useFileTransport‘ to false and configure a transport
 78             // for the mailer to send real emails.
 79             ‘useFileTransport‘ => false,
 80             ‘transport‘ => [
 81                 ‘class‘ => ‘Swift_SmtpTransport‘,
 82                 ‘host‘ => ‘smtp.163.com‘,
 83                 ‘username‘ => ‘[email protected]‘, //用户名
 84                 ‘password‘ => ‘xxxx‘,
 85                 ‘port‘ => ‘25‘,
 86                 ‘encryption‘ => ‘tls‘,
 87             ],
 88         ],
 89         ‘log‘ => [
 90             ‘traceLevel‘ => YII_DEBUG ? 3 : 0,
 91             ‘targets‘ => [
 92                 [
 93                     ‘class‘ => ‘yii\log\FileTarget‘,
 94                     ‘levels‘ => [‘error‘, ‘warning‘],
 95                 ],
 96             ],
 97         ],
 98         ‘urlManager‘ => [
 99             ‘enablePrettyUrl‘ => true,
100             ‘showScriptName‘ => false,
101             ‘rules‘ => [
102             ],
103         ],
104         ‘i18n‘ => [
105             ‘translations‘ => [
106                 ‘app*‘ => [
107                     ‘class‘ => ‘yii\i18n\PhpMessageSource‘,
108                     ‘basePath‘ => ‘@app/messages‘,
109                     ‘sourceLanguage‘ => ‘en-US‘,
110                     ‘fileMap‘ => [
111                         ‘app‘ => ‘app.php‘,
112 //                        ‘app/error‘ => ‘error.php‘,
113                     ],
114                 ],
115             ],
116         ],
117         ‘db‘ => require(__DIR__ . ‘/db.php‘),
118         ‘assetManager‘ => [
119             ‘linkAssets‘ => true,
120             ‘bundles‘ => [
121                 ‘yii\web\JqueryAsset‘ => [
122 //                    ‘sourcePath‘ => null,
123                     ‘jsOptions‘ => [
124                         ‘position‘ => \yii\web\View::POS_HEAD
125                     ],
126 //                    ‘js‘ => [
127 //                        ‘jquery.js‘ => Yii::getAlias(‘@supportStaticHost‘) . ‘/js/vendor/jquery.min.js‘,
128 //                    ],
129                 ],
130 //                ‘yii\bootstrap\BootstrapAsset‘ => [
131 ////                    ‘sourcePath‘ => null,
132 //                    ‘css‘ => [
133 ////                        ‘css/bootstrap.css‘ => Yii::getAlias(‘@supportStaticHost‘) . ‘/bootstrap/css/bootstrap.min.css‘
134 //                    ],
135 //                    ‘jsOptions‘ => [
136 //                        ‘position‘ => \yii\web\View::POS_HEAD
137 //                    ],
138 //                ],
139                 ‘yii\bootstrap\BootstrapPluginAsset‘ => [
140                     ‘jsOptions‘ => [
141                         ‘position‘ => \yii\web\View::POS_HEAD
142                     ],
143                 ],
144             ],
145         ],
146         //rbac配置
147         ‘authManager‘ => [
148             ‘class‘ => ‘app\helpers\rbac\DbManager‘,
149         ]
150
151     ],
152     ‘params‘ => $params,
153     ‘modules‘ => require(__DIR__ . ‘/modules.php‘),
154 ];
155
156 if (YII_ENV_DEV) {
157     // configuration adjustments for ‘dev‘ environment
158     $config[‘bootstrap‘][] = ‘debug‘;
159     $config[‘modules‘][‘debug‘] = [
160         ‘class‘ => ‘yii\debug\Module‘,
161     ];
162
163     $config[‘bootstrap‘][] = ‘gii‘;
164     $config[‘modules‘][‘gii‘] = [
165         ‘class‘ => ‘yii\gii\Module‘,
166     ];
167 }
168 /*echo "<pre>";
169 print_r($config[‘modules‘]);exit;*/
170 return $config;
时间: 2024-07-31 07:46:18

Yii 配置信息 配置项(Configuration)的相关文章

读取配置信息

ASP.NET Core的配置(1):读取配置信息 提到“配置”二字,我想绝大部分.NET开发人员脑海中会立马浮现出两个特殊文件的身影,那就是我们再熟悉不过的app.config和web.config,多年以来我们已经习惯了将结构化的配置信息定义在这两个文件之中.到了.NET Core的时候,很多我们习以为常的东西都发生了改变,其中也包括定义配置的方式.总的来说,新的配置系统显得更加轻量级,并且具有更好的扩展性,其最大的特点就是支持多样化的数据源.我们可以采用内存的变量作为配置的数据源,也可以直

使用Apache Commons Configuration读取配置信息

在项目中使用一些比较新的库总会给你带来很多快乐,在这篇文章中,我将会给你介绍一个在Java中读取配置文件的框架--Apache Commons Configuration framework. 你会了解到 ·从XML文件中获取数据 ·访问环境变量 ·连接不同类型的配置信息(基于XML的,基于环境变量的,等等) ·在程序改变后自动重新加载配置. 在我们的示例中将会使用XML文件和环境变量的两种方式存储一个数据库的配置信息(开发.测试.产品,等等).接下来你将会看到具体的内容,但是首先先配置一下Ma

HTTP常用配置信息详解

一.安装httpd 二.相关文件路径 三.配置文件详解 四.转载比较详细的HTTP配置中英文对照 一.安装httpd 1.安装方式:yum源.rpm包.源码包编译安装,这里为了方便使用yum源安装 [[email protected] html]# yum install -y httpd 可以安装本地帮助手册 [[email protected] conf]# yum install -y httpd-manual 访问地址http://httpd主机ip/manual/ 2.开启服务 [[e

Nuget~让包包带上自己的配置信息

我们知道一般开发组件之后,组件都有相关配置项,最常见的作法就是把它写到web.config里,而如果你将这个文件直接放到nuget里打包,在进行安装包包时,会提示你这个文件已经存在,不能去覆盖原来的config文件,这时,我们只能将配置信息写到别一个文本文件里,而使用者在安装包包后,还要手动将信息拷贝到自己的config文件,确实挺无奈的,没人愿意干这种重复的活! 解决这种现状 使用web.config.transform文件,将自己个性的信息写在里面,它将自动合并到现有config文件中 例如

JavaWEB中读取配置信息

第一种方法是使用java.io和java.util包,缺点是路径的概念要清晰, 例子: Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream("/common.properties"); try { prop.load(in); pool = new JedisPool(config, prop.getProperty("pay.redis.url"))

SERVERAID 8K和8K-L阵列卡在添加新硬盘时会丢失阵列配置信息

客户有一台IBM X3400需要扩容本地硬盘,去之前以为和IBM x3650M4等服务器类似,就没有多查资料,到现场后发现阵列卡型号是SERVERAID 8K,整个配置界面与x3650M4 的webbios配置阵列卡完全不同,没敢贸然操作,上网查了查资料,一些注意的地方和大家分享一下. 使用ARC配置ServeRAID_8k-l8k8i图文手册,已经上传到这里http://down.51cto.com/data/1357299 适用机型: 所有System x3400; 所有System x35

Jenkins: 配置信息变更历史

像 Jenkins 这样的系统,使用的过程就是配置文件变更的过程.如果能够对配置文件的变更进行跟踪管理,将极大的提高系统的可用性.Job Configuration History 插件就是这么一款实用而精巧的组件.很显然,相对于它的功能而言,它的名字实在是太低调了.因为它不仅能处理 Job Configuration 的变更历史,还能够处理系统级别的配置变更历史. 安装 Job Configuration History 插件 在 Jenkins->Plugin Manager 界面中选择 &qu

11g RAC集群启动关闭、各种资源检查、配置信息查看汇总。

简要:一:集群的启动与关闭 1. rac集群的手动启动[[email protected] bin]# ./crsctl start cluster -all2. 查看rac集群的状态[[email protected] bin]# ./crsctl stat res -t3. rac集群的关闭[[email protected] bin]# ./crscrl stop cluster -all--------------------------------二:集群的各种资源状态的检查 1. 检

MyBatis 源码分析——配置信息

MyBatis框架的启动前期需要加载相关的XML配置信息.从官网上我们可以了解到他具有十几个节点.其中笔者认为比较重要的节点是settings节点.properties节点.environments节点. transactionManager节点.至于相关的作用到官网看过一篇都会明白. MyBatis框架的XML配置到底有几个节点,这个必须去查看一下相关的DTD文件才行.DTA文件就在包名为org.apache.ibatis.builder.xml的下面.由于显示的问题笔者只复制出部分来. <?