gentlefoxmedia supports this item


7 comments found.

Looks handy. Good luck.


how to use this class with ?

I register my class with flight, and then use it when need.

I would like to do the same with your class, example:

Flight::register(‘HTML’, ‘objHtml’);

then use it where I want with:

$html = Flight::objHtml();

echo $html->a(‘');

Ok, if you want it this way. Do the following:

Create a class called HtmlObject.

class htmlObject { function __call($method, $arguments) { return call_user_func(‘HTML::’ .$method, $arguments); } }

It’s been a while since I’ve done this but I think it’s correct. It will allow you to register this htmlObject as a class for Flight and you can instantiate it.

It calls the original, static HTML class though.

Hi, thanks for tips.

However using flightphp, I don’t need make this new class, since flightphp use similar method.

I make only one file and put html, element and ielement class into this file, and I remove namespace.

then I just call:

Flight::register(‘html’, ‘HTML’);

and I can use it:

$html = Flight::html();

$html->a(‘', ‘Google’);

Thanks for all your help! Going to integrate all your classes together.

I have this error running your example:

Fatal error: Constructor Afflicto\HTML\HTML::html() cannot be static in C:\WebServer\xampp\htdocs\test\html\html\HTML.php on line 736

Can you tell me what version of PHP you’re using?

5.3.1 … you said it supported 5.3 and 5.4 correct?

Yes, it is supposed to. I’ve never seen this error though. Anyway, you can safely remove or rename that method.

Small issue on Element class, method base()

I think this: if ($target) $el->atr(‘target’, $target);

should be:

if ($target) $el->attr(‘target’, $target);

“attr” and not “atr”

Thanks, that’s now fixed in the next update!


I have two questions.

How to extend class without using macro ( I don’t want use macro, since this is used on all files)

I mean, I want add a new elements, like new grid system of bootstrap.

html::row($content, $attributes);

this will print the div.row > div.col-lg-12

Second question is method “with”, how to use it?


I would recommend that you use the macro system. It functions exactly as if it were a method on the HTML Class.

Create a new file ‘htmlMacros.php’ and require_once the html class then define all your macros and include it in your main application.

As for the ‘with’ method on the elements, it allows you to add content to the elements.

For example:
echo HTML::div()->with(array(
  HTML::p("another paragraph"),
$div = HTML::div();

the ‘with’ method takes either a string value, an object with a ‘display’ method or an array of those.

Many thanks!

No problem! and thanks for reporting bugs :)

Report a possible issue:

On img() method you add true for endTag, which should be false, since img tag have not close tag:

static function img($src, $attributes = array()) {
    $el = new Element('img', false, null, $attributes);
    $el->attr('src', $src);
    return $el;


Thanks, that’s now fixed!

I just purchaed it. Not so happy at the moment as it looks as I can not build a complete HTML page (starting with Doctype), implementing a head and a body section by using this:

$doc = HTML::html() .... this will put a class into the tag $doc->head = HTML::head(); ...

Maybe a bit more documentation would be good—at least for me.

Maybe you can provide an example for a complete html page with head, body, a few divs, etc.