Download the PHP package tlr/html-table-builder without Composer
On this page you can find all versions of the php package tlr/html-table-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package html-table-builder
HTML Table Builder
A class-based, "fluent" HTML table builder in PHP.
Installation
Basic Usage
You can see much of the functionality in the above example. More detailed explanations are below.
Reference
Table
The table object represents a top level HTML table.
See Classable
below for information on setting the rows' classes.
See Attributable
below for information on setting other attributes on the cell element.
It has four other main methods.
$table->render()
This is a helpful shortcut to doing the following:
If you want to pretty print the HTML in your table, you can set it like so:
$table->header()
$table->body()
$table->footer()
These all return a table section object (see below).
These will be initialised the first time you call the function, so if you never call ->header()
, then a <thead>
section will not be rendered.
You can call them multiple times, and they will return the same object.
Section (thead
, tbody
, tfoot
)
These objects represent sections in a table.
See Classable
below for information on setting the rows' classes.
See Attributable
below for information on setting other attributes on the cell element.
There are two other methods to talk about here.
$section->row()
This initialises and returns a new Row
object. Calling it multiple times will add multiple rows to the table.
$section->nextRow(Row $current)
Returns the next row in its children from the one passed to it.
Throws an error if passed a row that is not one of its children.
See the code example for the logic of how this works.
Row
These objects represent rows in a table section.
See Classable
below for information on setting the rows' classes.
See Attributable
below for information on setting other attributes on the cell element.
$row->addCell(CellInterface $cell)
This adds a new cell to the row. You can use this to add a custom cell to the row.
The following helper methods use this method to add the basic included cell types.
$row->cell(string $content = null)
$row->linkCell(string $link)
$row->imageCell(string $src)
Cells
These objects represent cells in a table row.
See Spannable
below for information on setting the column spanning.
See Classable
below for information on setting the cells' classes.
See Attributable
below for information on setting other attributes on the cell element.
Content Cell
This is the default cell. It is fairly versatile, although basic.
You can set the content on initialiastaion, or by calling the ->content(string $content)
method.
The default behaviour is to escape the content. If you want to override this, chain in the ->dontEscape()
or ->raw()
methods.
There is a ->wrapContent(string $open, string $content, string $close)
method. This lets you enter some unescaped HTML that wrap some escaped content. Essentially, all this does is escape the $content
value, then concatenate them in order, and set the cell to ->raw()
or ->dontEscape()
. Nevertheless, it can still be helpful - allowing you to mix your own unescaped HTML with some content that should be escaped.
As with any unescaped content, it is up to you to ensure the HTML is valid.
See below for some examples.
Link Cell
A link cell is a cell with a link in it. Other than the link argument to its constructor, it behaves like a ContentCell
Image Cell
Traits
Spannable
On the Cell
objects, you can call:
This returns the element object for chaining.
Classable
On any of the element objects - Table
, Section
, Row
, Cell
, you can set the class. The following three examples all result in <table class="ui table">
:
This returns the element object for chaining.
Attributable
You can set any other HTML attribute:
This returns the element object for chaining.