D
D
del9937882017-01-27 00:47:16
Yii
del993788, 2017-01-27 00:47:16

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?
<?= Html::img("@web/images/img.png")?>
<img src="/images/img.png">

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaliy Orlov, 2017-01-27
@del993788

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.

S
Snewer, 2017-01-27
@Snewer

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

R
Rustamka Vorontsov, 2017-01-27
@rmfordev

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 question

Ask a Question

731 491 924 answers to any question