配置項(Configuration)
說到配置項,讀者朋友們第一反應是不是Yii的配置文件?這是一段配置文件的代碼:
、return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
... ...
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => 'cache1.digpage.com',
'port' => 11211,
'weight' => 60,
],
[
'host' => 'cache2.digpage.com',
'port' => 11211,
'weight' => 40,
],
],
],
],
'params' => [...],
];
Yii中許多地方都要用到配置項,Yii應用自身和其他幾乎一切類對象的創建、初始化、配置都要用到配置項。 配置項是針對對象而言的,也就是說,配置項一定是用于配置某一個對象,用于初始化或配置對象的屬性。 關于屬性的有關內容,請查看 屬性(Property) 。