Trait yii\base\StaticInstanceTrait
Implemented by | yii\base\DynamicModel, yii\base\Model, yii\data\ActiveDataFilter, yii\data\DataFilter, yii\db\ActiveRecord, yii\db\BaseActiveRecord |
---|---|
Available since version | 2.0.13 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/base/StaticInstanceTrait.php |
StaticInstanceTrait provides methods to satisfy yii\base\StaticInstanceInterface interface.
See also yii\base\StaticInstanceInterface.
Public Methods
Method | Description | Defined By |
---|---|---|
instance() | Returns static class instance, which can be used to obtain meta information. | yii\base\StaticInstanceTrait |
Method Details
Returns static class instance, which can be used to obtain meta information.
public static static instance ( $refresh = false ) | ||
$refresh | boolean |
Whether to re-create static instance even, if it is already cached. |
return | static |
Class instance. |
---|
public static function instance($refresh = false)
{
$className = get_called_class();
if ($refresh || !isset(self::$_instances[$className])) {
self::$_instances[$className] = Yii::createObject($className);
}
return self::$_instances[$className];
}
Signup or Login in order to comment.