Class Html (namespace Nette\Web)


HTML helper.

  1.  $anchor Html::el('a')->href($link)->setText('Nette');
  2.  $el->class 'myclass';
  3.  echo $el;
  4.  
  5.  echo $el->startTag()$el->endTag();

Object
   |
   --Html

Implements interfaces:

ArrayAccess (internal interface), Countable (internal interface), IteratorAggregate (internal interface)
Author: David Grudl
Copyright: Copyright (c) 2004, 2009 David Grudl
Located: in /Web/Html.php (line 44)
Method Summary
Html
add (Html|string $child)
Adds new element's child.
string
Returns element's attributes.
int
count ()
Required by the \Countable interface.
Html
create (string $name, [array|string $attrs = NULL])
Creates and adds a new Html child.
static Html
el ([string $name = NULL], [array|string $attrs = NULL])
Static factory.
string
endTag ()
Returns element's end tag.
void
Returns all of children.
RecursiveIterator
getIterator ([bool $deep = FALSE], string 1)
Iterates over a elements.
string
getName ()
Returns element's name.
string
getText ()
Gets element's textual content.
Html
href (string $path, [array $query = NULL])
Special setter for element's attribute.
Html
insert (int $index, Html $child, [bool $replace = FALSE])
Inserts child node.
bool
isEmpty ()
Is element empty?
bool
offsetExists (int $index)
Exists child node? (\ArrayAccess implementation).
mixed
offsetGet (int $index)
Returns child node (\ArrayAccess implementation).
void
offsetSet (int $index, Html $child)
Inserts (replaces) child node (\ArrayAccess implementation).
void
offsetUnset (int $index)
Removes child node (\ArrayAccess implementation).
void
Removed all children.
string
render ([int $indent = NULL])
Renders element's start tag, content and end tag.
Html
setHtml (string $html)
Sets element's HTML content.
Html
setName (string $name, [bool $isEmpty = NULL])
Changes element's name.
Html
setText (string $text, [$isHtml = FALSE])
Sets element's textual content.
string
Returns element's start tag.
Html
__call (string $m, array $args)
Overloaded setter for element's attribute.
void
__clone ()
Clones all children too.
& mixed
__get (string $name)
Overloaded getter for element's attribute.
void
__set (string $name, mixed $value)
Overloaded setter for element's attribute.
void
void
__unset (string $name)
Overloaded unsetter for element's attribute.
Methods Inherited From Object
Object::extensionMethod(), Object::getClass(), Object::getReflection(), Object::__call(), Object::__callStatic(), Object::__get(), Object::__isset(), Object::__set(), Object::__unset()
Variable Summary
array $attrs array()

line 53

element's attributes
protected array $children array()

line 56

of Html | string nodes
static array $emptyElements array('img'=>1,'hr'=>1,'br'=>1,'input'=>1,'meta'=>1,'area'=>1,...

line 62

empty elements
static bool $xhtml TRUE

line 59

use XHTML syntax?

Method Details

line 282

add

public Html add (Html|string $child)

Adds new element's child.

Input
Html|string $child child node
Output
Html provides a fluent interface

line 507

attributes

public string attributes ()

Returns element's attributes.

Output
string  

line 385

count

public int count ()

Required by the \Countable interface.

Implementation of:

Countable::count
Output
int  

line 295

create

public Html create (string $name, [array|string $attrs = NULL])

Creates and adds a new Html child.

Input
string $name elements's name
array|string $attrs element's attributes (or textual content)
Output
Html created element

line 73

el

public static Html el ([string $name = NULL], [array|string $attrs = NULL])

Static factory.

Input
string $name element name (or NULL)
array|string $attrs element's attributes (or textual content)
Output
Html  

line 496

endTag

public string endTag ()

Returns element's end tag.

Output
string  

line 426

getChildren

public void getChildren ()

Returns all of children.

return array

Output
void  

line 409

getIterator

public RecursiveIterator getIterator ([bool $deep = FALSE], string 1)

Iterates over a elements.

Implementation of:

IteratorAggregate::getIterator
Input
bool $deep recursive?
string 1 class types filter
Output
RecursiveIterator  

line 118

getName

public string getName ()

Returns element's name.

Output
string  

line 265

getText

public string getText ()

Gets element's textual content.

Output
string  

line 205

href

public Html href (string $path, [array $query = NULL])

Special setter for element's attribute.

Input
string $path path
array $query query
Output
Html provides a fluent interface

line 311

insert

public Html insert (int $index, Html $child, [bool $replace = FALSE])

Inserts child node.

Input
int $index
Html $child node
bool $replace
Output
Html provides a fluent interface
Throws
throws Exception

line 129

isEmpty

public bool isEmpty ()

Is element empty?

Output
bool  

line 360

offsetExists

public bool offsetExists (int $index)

Exists child node? (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetExists
Input
int $index index
Output
bool  

line 348

offsetGet

public mixed offsetGet (int $index)

Returns child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetGet
Input
int $index index
Output
mixed  

line 336

offsetSet

public void offsetSet (int $index, Html $child)

Inserts (replaces) child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetSet
Input
int $index
Html $child node
Output
void  

line 372

offsetUnset

public void offsetUnset (int $index)

Removes child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetUnset
Input
int $index index
Output
void  

line 396

removeChildren

public void removeChildren ()

Removed all children.

Output
void  

line 438

render

public string render ([int $indent = NULL])

Renders element's start tag, content and end tag.

Input
int $indent indent
Output
string  

line 223

setHtml

public Html setHtml (string $html)

Sets element's HTML content.

Input
string $html
Output
Html provides a fluent interface
Throws
throws InvalidArgumentException

line 101

setName

public Html setName (string $name, [bool $isEmpty = NULL])

Changes element's name.

Input
string $name
bool $isEmpty Is element empty?
Output
Html provides a fluent interface
Throws
throws InvalidArgumentException

line 248

setText

public Html setText (string $text, [$isHtml = FALSE])

Sets element's textual content.

Input
string $text
$isHtml
Output
Html provides a fluent interface
Throws
throws InvalidArgumentException

line 480

startTag

public string startTag ()

Returns element's start tag.

Output
string  

line 179

__call

public Html __call (string $m, array $args)

Overloaded setter for element's attribute.

Input
string $m HTML attribute name
array $args (string) HTML attribute value or pair?
Output
Html provides a fluent interface

line 559

__clone

public void __clone ()

Clones all children too.

Output
void  

line 154

__get

public mixed & __get (string $name)

Overloaded getter for element's attribute.

Input
string $name HTML attribute name
Output
& mixed HTML attribute value

line 142

__set

public void __set (string $name, mixed $value)

Overloaded setter for element's attribute.

Input
string $name HTML attribute name
mixed $value HTML attribute value
Output
void  

line 469

__toString

public void __toString ()

Output
void  

line 166

__unset

public void __unset (string $name)

Overloaded unsetter for element's attribute.

Input
string $name HTML attribute name
Output
void