set() public method
Registers a component definition with this locator.
For example,
// a class name $locator->set('cache', 'yii\caching\FileCache'); // a configuration array $locator->set('db', [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', 'username' => 'root', 'password' => '', 'charset' => 'utf8', ]); // an anonymous function $locator->set('cache', function ($params) { return new \yii\caching\FileCache; }); // an instance $locator->set('cache', new \yii\caching\FileCache);
If a component definition with the same ID already exists, it will be overwritten.
public void set ( $id, $definition ) | ||
---|---|---|
$id | string |
Component ID (e.g. |
$definition | mixed |
The component definition to be registered with this locator. It can be one of the following:
|
throws | yii\base\InvalidConfigException |
if the definition is an invalid configuration array |
Please login to continue.