Answer the question
In order to leave comments, you need to log in
Why does Yii2 not see the widget, and how can I fix it?
Good afternoon, I'm learning to deal with widgets in the advanced version. I want to keep all my widgets in the frontend/widgets folder (for me it's more convenient and seems more logical). So I created a widget with my views
in the controller, I wrote:
<?php
namespace app\MyWidget;
use yii\base\Widget;
class breadcrumb extends Widget {
public function run(){
return "hello World";
}
}
use app\MyWidget;
MyWidget\breadcrumb::widget();
Class 'app\MyWidget\breadcrumb' not found
Answer the question
In order to leave comments, you need to log in
where did app come from if it's advanced and not basic? Where did MyWidget come from? Actually, the error tells you that it does not understand where 'app\MyWidget' came from and what you decided that it should be.
As I understand it, instead of it, namespace app\MyWidget;
I should namespace frontend/widgets/breadcrumb;
also not quite understand what the controller and model do in your widget? Are you sure you are not confusing a widget and a module?
And a very big request, class names with a capital letter. See how the yii developers worked hard pressing shift until the pain in the little finger (Widget), and you are lazy (breadcrumb)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question