I’ve found a framework that handles the views in a different way than just plain html. To be honest, I’ve no idea how are the big frameworks handling this issue because I’ve mostly worked with some tiny frameworks, so that’s why it was an interesting thing for me. A quick example:
Instead of writing
<h2>Click on this <a href="www.example.com">example</a></h2>
You’d have to type
echo $html->h2('Click on this' . $html->link('www.example.com', 'example'));
So, my question is which one is better? Isn’t plain html going to be faster? And let’s say more understandable for others? Or let’s leave the understandable part away, I want to know more about the performance and maybe other stuff that people know and can be mentioned on this issue.
CodeIgniter is one of the frameworks that provides an HTML helper to allow you to generate HTML through PHP code (like the latter case in your question).
While this will be marginally slower, the advantage is it ensures valid HTML is output. Take this example:
<h2>This is a header without a closing tagThe above is a common mistake which will fail silently. However, you cannot make the same mistake if you use the HTML helper function
echo heading('This is a header',2);As for readability, anyone familiar with PHP should be able to understand either code fragment with little to no difficulty.