For two days I have been looking for an answer to my question, I began to get acquainted with yii2 a week ago). I am writing a widget where I connect to a table from a database
$ my = ‘Mybd’ :: find () -> all ();
return $ this-> render (‘Mywidget’, [‘bdr’ => $ my]);
Some people assure me that this is not possible, they do not offer a solution in exchange or a direction as needed. I ask for help with this issue, there is not enough knowledge on my own.
class Mywidget extends Widget
public function run()
$my = 'Mybd'::find() -> all();
return $ this-> render ('Mywidget', ['widgetbd' =>$my]);
sorry my mistake.
My task is to display images from the database as a menu in the layout, unfortunately, I don’t know how to do it correctly, I decided using the widget, the query works as I need, but I think it’s wrong, but to solve This problem alone can not.
I pass in the view widget, there is already html markup and foreach, everything works perfectly and as I need. But I was told in numerous forums that this is extremely not true, but how to do it right no one gave an answer) for this reason I turned to your forum because I couldn’t find any detailed information on this issue.
I think that this widget should include the necessary db accessing inside it. Or you have to do it in each and every controller and pass the query result to the widget every time you want to use it. That’s sheer nonsense. Don’t give a damn to what MVC idiots say, if it will make things unnecessarily complicated.
I was really just reacting to the “Don’t give a damn to what MVC idiots say, if it will make things unnecessarily complicated.” advice and not trying to be mean to you by any ways! Sorry if you read that otherwise.
There is really no shame in asking while learning, and I’ll be glad to help you with your next question (that is, if @softark doesn’t beat me to it first)
Thank you, @machour. I really appreciate your thumb up.
@FrelNewBew, I didn’t have any intention to insult you, my friend. I was just angry at the people who gave you a false advice to stick to MVC without showing you how to do it. They only know the word “MVC” but have no brain to think for themselves.