Answer the question
In order to leave comments, you need to log in
How to get the name of a component in Yii2?
In configuration like this:
<?php
return [
'components' => [
'testComponent' => [
'class' => 'common\components\TestComponent',
],
],
];
<?php
namespace common\components;
class TestComponent extends Component
{
public function create()
{
$config = ArrayHelper::getValue(Yii::$app->components, '{Как тут вывести имя "testComponent"}', []);
return Yii::createObject($config);
}
}
Answer the question
In order to leave comments, you need to log in
If I understand you correctly, then in the configuration file, set the name of the component.
'components' => [
'testComponent' => [
'class' => 'app\components\TestComponent',
'name' => 'testComponent'
]
]
class TestComponent extends Component
{
public $name;
public function create()
{
$config = ArrayHelper::getValue(Yii::$app->components, Yii::$app->testComponent->name, []);
return Yii::createObject($config);
}
}
Yii::$app->testComponent->className()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question