Why use CakePHP's HTML Helpers?
Working on my first CakePHP site, and I'm confused as to when/why I should use CakePHP's HTML Helpers. They seem GREAT for forms - but for links, images, divs...etc, they seem overkill.
开发者_开发知识库Am I overlooking something? What's the benefit? Do you / should I use the helpers for everything, just forms, or nothing?
(I did find a short discussion similar to this on stackoverflow, but it was more directed at specific code, not the code in general.) Thanks in advance for any help!
I use the helpers mostly for forms, links and images. I tend to have about 3 environments my app run on (local, dev and production). Local and dev usually run in a subfolder setup and production runs on a root domain. The reason I use the helpers for links and images is because this way I don't need to worry about the base url when linking and pointing to images. It's very easy and portable.
The Form helper, of course, is invaluable when you want to make the automagic fields inside the form.
And then you have the script and the meta helpers to make it easer to manage your custom header tags/scripts/styles.
For images and links, I see at least one major advantage of using helpers : those will deal with absolute-URLs and http
/https
protocols (for href/src that point to your website), no matter where your application is deployed.
Another reason to use the helpers is to avoid bouncing back and forth between writing PHP code and HTML in your .ctp
files.
精彩评论