Answer the question
In order to leave comments, you need to log in
Why does the Yii2 autoloader not see the class when accessing its constant?
A typical Yii2 Basic
application . Just a fresh clone.
git clone [email protected]:yiisoft/yii2-app-basic.git
cd yii2-app-basic
composer install
./yii
diff --git a/components/Something.php b/components/Something.php
new file mode 100644
index 0000000..18e0379
--- /dev/null
+++ b/components/Something.php
@@ -0,0 +1,10 @@
+namespace app\components;
+
+use yii\base\Component;
+
+class Something extends Component {
+
+ const A = [];
+
+ public $b;
+}
\ No newline at end of file
diff --git a/config/console.php b/config/console.php
index 299656a..42e80d5 100644
--- a/config/console.php
+++ b/config/console.php
@@ -13,6 +13,14 @@ $config = [
'@npm' => '@vendor/npm-asset',
'@tests' => '@app/tests',
],
+ 'container' => [
+ 'definitions' => [
+ \app\components\Something::class => [
+ 'class' => \app\components\Something::class,
+ 'b' => \app\components\Something::A
+ ],
+ ],
+ ],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
/vhosts/yii2-app-basic$ ./yii
PHP Fatal error: Uncaught Error: Class 'app\components\Something' not found in /vhosts/yii2-app-basic/config/console.php:20
Stack trace:
#0 /vhosts/yii2-app-basic/yii(17): require()
#1 {main}
thrown in /vhosts/yii2-app-basic/config/console.php on line 20
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question