Advanced application template.

I have a module in common\modules\setting\Module

A component is required. Inside the module I make the "components" folder: common\modules\setting\components In this folder I put a file named SettingComponent.php File contents:

 namespace common\modules\setting\components; use yii\base\Component; class SettingComponent extends Component { // some code... } 

In common\config\main.php I connect the component as follows:

 [ 'components' => [ 'setting' => [ 'class' => 'common\modules\setting\components\SettingComponent', ], // ... ], ]; 

As a result, I get the error:

 ReflectionException Class common\modules\setting\components\SettingComponent does not exist 

Here is the hierarchy just in case:

enter image description here

What am I doing wrong?

  • Maybe because it is necessary to write in the config not in components , but in modules ? yiiframework.com/doc-2.0/… ......... youtu.be/GtHB58-JA38 - Alexey Shimansky
  • What for? I connect the module this way: 'setting' => [ 'class' => common\modules\setting\Module::className() ] I need so that I can access this component anywhere in the application like this: \Yii::$app->setting - LostDok 2:19 pm

1 answer 1

In the files, you wrote it all right, but how did you call the directory? :)

enter image description here

  • Thank you very much. Like 10 times already checked, re-spelled and did not notice ... Horror. 4 hours spent: (((Thanks again. - LostDok
  • 3
    It happens) In this case, it is more useful to relax a bit and look with a fresh look, so as not to kill 4 hours. - white-imp