HTML
The role of the HtmlHelper in CakePHP is to make HTML-related options easier, faster, and more resilient to change. Using this helper will enable your application to be more light on its feet, and more flexible on where it is placed in relation to the root of a domain.
The HtmlHelper's role has changed significantly since CakePHP 1.1. Form related methods have been deprecated and moved to the new FormHelper. If you're looking for help with HTML forms, check out the new FormHelper.
Before we look at HtmlHelper's methods, you'll need to know about a few configuration and usage situations that will help you use this class. First is a core configuration constant called AUTO_OUTPUT. If AUTO_OUTPUT is set to true in the core configuration file for your application (/app/config/core.php), the HtmlHelper will automatically output the contents of the tag, rather than just returning the value. This has been done in an effort to assuage those who dislike short tags (<?= ?>) or many echo() calls in their view code. Functions that feature the $return parameter allow you to force-override the settings in your core config. Set $return to true if you'd like the HtmlHelper to return the HTML code regardless of the value of AUTO_OUTPUT.
Many HtmlHelper methods also include a $htmlAttributes parameter, that allow you to tack on any extra attributes on your tags. Here are a few examples of how to use the $htmlAttributes parameter:
Простой текстDesired attributes: <tag class="someClass" />Array parameter: array('class'=>'someClass')Desired attributes: <tag name="foo" value="bar" />Array parameter: array('name' => 'foo', 'value' => 'bar')
The HtmlHelper is available in all views by default. If you're getting an error informing you that it isn't there, it's usually due to its name being missing from a manually configured $helpers controller variable.


Коментарии:
Добавить коментарий