Open-Source PHP Framework - Designed for rapid development of performance-oriented scalable applications

HTML Helper

API >> mvc >> helpers >> html

This helper provides HTML abstraction to simplify your view/element/layout

Code wrappers

These produce XHTML-strict/XML-valid containers for:

  • - a JavaScript file
  • - a block of JavaScript code
  • - a block of JavaScript code that will only execute once (even if echoed out twice) and will try to be put added to the document head, if the head has already been echoed out then this method will returned the code block to echo out inline.
  • - a CSS file
  • - a block of CSS code
  • - a block of CSS code that will only execute once (even if echoed out twice) and will try to be put added to the document head, if the head has already been echoed out then this method will returned the code block to echo out inline.

Eg.:

Some wrappers can accept optional additional arguments, the css and cssInline can accept an extra argument for media type, eg.:

Basic wrappers

Basic wrappers also exist solely as an alternative formatting that makes it faster to modify HTML tag types at a later time (eg. changing an h2 to h3,) use if you like or just ignore and use regular HTML:

  • through

setDocType($docType)

Allows modification of the docType header. This method must be called before the method.

Can either set to an actual doctype definition like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">;

Or to one of the preset values (not case-sensitive):

  • (alias for the most-strict Mobile DTD, currently 1.2)
  • (alias for XHTML Mobile 1.2)
  • (alias for XHTML Mobile 1.1)
  • (alias for XHTML Mobile 1.0)
  • (Alias for XHTML 1.1, the default DTD, there is no need to apply this method for an XHTML 1.1 doctype)
  • (this is the default DTD, there is no need to apply this method for an XHTML 1.1 doctype)
  • (Alias for XHTML 1.0 Strict)
  • (Alias for HTML 4.01)

header($args) and footer($args) methods

and methods exist to open and close the HTML body and are meant only for use in your layout. Both take a single associative array as an argument.

Header()

Argument keys are:

  • - this is the only required argument
  • - default is UTF-8
  • - this expects an array of key-value pairs and will convert them to meta http-equiv statements
  • - same as metaheader except converts to meta name statements
  • - URL of an ICO file
  • - URL of an animated GIF file
  • - abstraction to the helper methods of the same names
  • - add raw markup into the head section

The only argument key that recognizes is - just pass along your Google Analytics tracker ID and your page traffic will be logged by Google Analytics.

jsLoad($library, $version = null, array $options = array())

Load a JavaScript library via Google's AJAX API.

Version is optional and can be exact (1.8.2) or just version-major (1 or 1.8)

The and arguments are only used when is a string (not an array.)

Syntax is very flexible:

jsTools($noJsWrapper = false)

Establishes a basic set of JavaScript tools, just before any JavaScript code that will use the tools.

This method will only operate from the first occurrence in your code, subsequent calls will not output anything but you should add it anyway as it will make sure that your code continues to work if you later remove a previous call to .

Tools provided:

  • - method is a direct replacement for that works in all JS-capable browsers Y2k and newer. Does virtuall the same thing as the in many JavaScript frameworks
  • object - defines a global storage space; use by appending your own properties, eg.:

Set to if calling from within a wrapper

flash($filename, array $args = array())

Displays a Flash movie using XHTML 1.1 syntax. First argument is the URL of the Flash file, second is an optional associative array containing any or all possible keys:

  • - an associative array of properties to add to the "object" HTML container
  • - an associative array of name/value pairs that will become individual "param" HTML containers.
  • - a string (text or HTML) that gets displayed when the user does not have the Flash plugin installed

isEven($number)

Convenience function that returns Boolean, true if the number you send it is even, false if odd.

str2ascii($str)

Converts a string to the ASCII equivelent. Note if you echo out the ASCII response in your browser it will get parsed and displayed as the original string (there will be no visible difference except when viewing the source code.)

getEmailLink($email)

Returns a spam-resistant email link. Just wrap around each email address, eg.:

link($href, $text = null, array $args = array())

Returns an accessibility-friendly link.

If you have an SSL page, it will prepend the http protocol (and your hostname) to all local URLs that do not include a protocol (http:// or https://), this makes it so that users who follow local non-SSL links from an SSL-enabled page do not stay in SSL mode when they leave the page.

- (Rrequired) relative or absolute URL

- optional, if omitted will be used as the

- optional, associative array elements become properties of the anchor tag. If you do not include a key for (required for W3C WAI AAA accessibility standards) a title will be made automatically for you based on the other data supplied.

- Set to an ID of an HTML container or a form text element and clicking the link will then load the data into the element via AJAX (if AJAX-capable browser, if not then this will work like an ordinary link.)

anchor(array $args)

This is similar to (above) but provides more fine-grained control; it also does not modify your links when in SSL mode. are the same as plus keys for and .

Use this method to create non-linked anchor tags (page anchors.)

img(array $args)

Returns an XHTML-valid accessibility-friendly image. All become properties of the img tag. An key is optional, but recommended, if omitted this helper will add an empty alt property per the Section 508 accessibility standards for images without contextual purpose.

image($src, $width = null, $height = null, $alt = '', $args = array())

Convenience function to simplify access the helper method. is required, and are optional as is which gets passed directy to .

Takes an associative array of links formated with URL as the key, title as the value and returns an HTML list of links. Valid values for the optional argument are (bulleted unordered list), (indented definition list) and (numeric ordered list.)

Your list values can contain subarrays to generate multi-tiered lists. Tier levels are infinite, you can nest an infinite amount of lists.

Creates a breadcrumb trail of links like:

API >> mvc >> helpers >> html

Each element in $links takes the URL as a key and the label as the value. If you add an element with a dynamically-assigned key (or a numeric key) it will display as plain text instead of as a link. Eg.:

would return:

alternator()

Simple method that returns an alternating Boolean each time you call it. This is useful to generate alternating background colors within looping structures.