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 would like to know if it is permissible to connect to the database in a widget in this way…
Sorry, I’m an idiot … I just had to ask this question and not type all this nonsense above.
I also don’t know why not. I’m satisfied because I’m new, I’m constantly asking on the forums, it’s said there that mvc breaks and I spent two days looking for an answer …
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.
To ask is the shame of one minute, and not to know is the shame of a lifetime. Be kinder to people who started to master the web 2 months ago) html, css, js, and php, their libraries and frameworks.
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.
sorry, it was addressed not to you) but to our dear friend) it turned out that he wasn’t for me and I wasn’t for you) in the end we all didn’t understand each other)