Answer the question
In order to leave comments, you need to log in
Why does yii2 need img helper if just img is shorter?
Tell me, why write
when you can write
?
The second option is at least shorter, but I myself have repeatedly noticed that html::img is used in the code. What for? "@web/images/img.png")
= Html::img(<img src="/images/img.png">
Answer the question
In order to leave comments, you need to log in
Helpers - automate actions. For example, even in your example, there is an alias (@web), which, when changed, will affect all places where it is specified. And in the case of regular html, you will have to change the paths manually. In addition, the Html::* helper methods have additional parameters, passing which you can influence the generated tag. And finally, it allows you not to mix html and php into a mess.
1. Sometimes it's more pleasant to work only with PHP code, and not use HTML at all.
2. At any time, you can change the behavior of all HTML stubs in the entire project.
3. Convenient when testing
squeeze "everything" out of the framework to the maximum, there are similar helpers on Laravel, but I don't use them, I stick to option number two.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question