\Hazaar\Html
Element
Abstract
Abstract base element class

This class is the base element class from which all HTML elements are built upon. It contains common methods and properties for all elements. It also enforces the use of __tostring() to output string renders of the object to form HTML content.

Tags

Since

1.0.0

Summary
Methods Properties Constants
No constants
Properties
$parameters
$parameters
$style
$style
$type
$type
Methods
__call()
__call($method, $args) : string

Chaining method to set a parameter on the element. As event parameters all start with ‘on’ this will check for event parameters and ensure that they are quoted correctly so that execution will not fail.

Tags

Since

1.2

Parameters

$method

No description

$args

No description

Returns

string
__construct()
__construct($type, $parameters = Array ( ) )

The HTML element constructor takes two arguments. The type of the element which is defined by the available types in the HTML standards. eg: A, DIV, SPAN, etc. The second argument is an array of parameters to apply to the element such as width, height, style, etc. The parameters are also defined by the current HTML standards.

The available types and parameters are not restricted by this class and so ANY type, valid or not, can be specified. It is up to the developer to ensure that the HTML element types they use adhere to the standards for which they are trying to comply.

Tags

Since

1.0.0

Parameters

$typestring

The HTML element type.

$parametersarray

An array of HTML parameters to apply to the element.

__get()
__get($key) : mixed

Magic method to allow getting of parameters by property access.

Tags

Since

1.0.0

Parameters

$keystring

The name of the parameter to return.

Returns

mixed

The value of the requested parameter. The data type of the value will be the same as that when it was originally set.

__set()
__set($key, $value) : \\Hazaar\\Html\Element

Set a parameter on the current HTML element

Tags

Since

1.0.0

Parameters

$keystring

The name of the parameter to set.

$value

No description

Returns

\\Hazaar\\Html\Element

Returns a ref to self.

__tostring()
__tostring() : string

Magic method to convert the element to a string.

Calls the methods renderObject() method to render the object as a string.

Tags

Since

1.0.0

Returns

string
addClass()
addClass($class) : $this
Adds a class to the HTML element

Parameters

$classstring

No description

Returns

\Hazaar\Html\this
asHtml()
asHtml() : string

Render the element as HTML using ascii special characters. This allows elements to easily be displayed without being rendered in the browser. Great for use inside

 elements.

Tags

Since

1.0.0

Returns

string
attr()
attr($key, $value = null) : \\Hazaar\\Html\Element

Get/Set an attribute on the current HTML element

Tags

Since

1.0.0

Parameters

$keystring

The name of the parameter to set.

$value

No description

Returns

\\Hazaar\\Html\Element

Returns a ref to self.

data()
data($key, $value)

Parameters

$key

No description

$value

No description

hasClass()
hasClass($class) : bool
Test if a class has been added to an HTML element

Parameters

$classstring

The class to check for

Returns

\Hazaar\Html\bool

TRUE if the class has been set

parameters()
parameters()
prop()
prop($key, $enabled = true) : Element
Enable or disable a property.

Some element types have properties that have no value. A good example is “checked” on a checkbox or radio, or “enabled” on an input. This method allows these properties to be added or removed without requiring a value.

Parameters

$keystring

The property to set on the element.

$enabledboolean

If TRUE the property will be added. If FALSE the property will not be added or it will be removed if it already exists.

Returns

\Hazaar\Html\Element
style()
style()
toggleClass()
toggleClass($class, $boolean = false) : $this;
Set's a class based on a boolean value.

This is handy for adding a class only if a boolean value is true and can be used as shorthand in place of in ‘if’ statement that selectively adds the class as this may not be desired in a view.

Parameters

$class

No description

$boolean

No description

Returns

\Hazaar\Html\this