D
D
darknet372017-05-01 20:41:57
Yii
darknet37, 2017-05-01 20:41:57

Yii2 cannot find the class even though it exists. What to do?

In the file frontend/views/layouts/main.php I write: Created a folder in the root components\MenuWidget.php Created a class:
<?php echo \app\components\MenuWidget::widget() ?>

<?php

namespace app\components;

use yii\base\Widget;
use common\models\Category;
use Yii;

class MenuWidget extends Widget
{

}

And further produces an error that such class is not found at all.
Error: Class 'app\components\MenuWidget' not found in D:\OpenServer\domains\site.name\frontend\views\layouts\main.php:132

In line 132, the code is written, which is on top
. What is the problem? what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-05-01
@darknet37

Place components directory in frontend
Namespace in widget file will be In main.php file it will be like this:

use frontend\components\MenuWidget;
........
echo MenuWidget::widget();

This is if you want to use the widget for the frontend only.
If you need to use it for the backend as well, then put the widget in common.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question