di\Container get()

get() public method

Returns an instance of the requested class.

You may provide constructor parameters ($params) and object configurations ($config) that will be used during the creation of the instance.

If the class implements yii\base\Configurable, the $config parameter will be passed as the last parameter to the class constructor; Otherwise, the configuration will be applied after the object is instantiated.

Note that if the class is declared to be singleton by calling setSingleton(), the same instance of the class will be returned each time this method is called. In this case, the constructor parameters and object configurations will be used only if the class is instantiated the first time.

public object get ( $class, $params = [], $config = [] )
$class string

The class name or an alias name (e.g. foo) that was previously registered via set() or setSingleton().

$params array

A list of constructor parameter values. The parameters should be provided in the order they appear in the constructor declaration. If you want to skip some parameters, you should index the remaining ones with the integers that represent their positions in the constructor parameter list.

$config array

A list of name-value pairs that will be used to initialize the object properties.

return object

An instance of the requested class.

throws yii\base\InvalidConfigException

if the class cannot be recognized or correspond to an invalid definition

throws yii\di\NotInstantiableException

If resolved to an abstract class or an interface (since 2.0.9)

doc_Yii
2016-10-30 17:01:04
Comments
Leave a Comment

Please login to continue.